diff options
author | Liong Sauw Ming <ming@teluu.com> | 2016-11-15 02:23:38 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2016-11-15 02:23:38 +0000 |
commit | 273b7964359262ab42523ea657f3c5313c151988 (patch) | |
tree | ed816ad80b978080c81a95315c09a8b76dc9ee62 | |
parent | e297e570a9b9eebe2209f3013972d560eae31f1a (diff) |
Re #1961: Fallback to CLOCK_MONOTONIC if /dev/alarm is not found, or getting ANDROID_ALARM_ELAPSED_REALTIME fails.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5482 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjlib/src/pj/os_timestamp_posix.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/pjlib/src/pj/os_timestamp_posix.c b/pjlib/src/pj/os_timestamp_posix.c index 8758d4d7..0cb4035f 100644 --- a/pjlib/src/pj/os_timestamp_posix.c +++ b/pjlib/src/pj/os_timestamp_posix.c @@ -180,18 +180,27 @@ void close_alarm_fd() PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) { struct timespec tp; + int err = -1; if (s_alarm_fd == -1) { int fd = open("/dev/alarm", O_RDONLY); if (fd >= 0) { s_alarm_fd = fd; pj_atexit(&close_alarm_fd); - } else { - return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); - } + } + } + + if (s_alarm_fd != -1) { + err = ioctl(s_alarm_fd, + ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp); + } + + if (err != 0) { + /* Fallback to CLOCK_MONOTONIC if /dev/alarm is not found, or + * getting ANDROID_ALARM_ELAPSED_REALTIME fails. + */ + err = clock_gettime(CLOCK_MONOTONIC, &tp); } - int err = ioctl(s_alarm_fd, - ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp); if (err != 0) { return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); |