Index: res/res_timing_timerfd.c =================================================================== --- res/res_timing_timerfd.c (revision 322064) +++ res/res_timing_timerfd.c (working copy) @@ -161,7 +161,28 @@ { uint64_t expirations; int read_result = 0; + struct timerfd_timer *our_timer, find_helper = { + .handle = handle, + }; + struct itimerspec timer_status; + + if (timerfd_gettime(handle, &timer_status)) { + ast_debug(1, "Call to timerfd_gettime() error: %s\n", strerror(errno)); + return; + } + if ((timer_status.it_value.tv_sec == 0) && (timer_status.it_value.tv_nsec == 0L)) { + ast_debug(1, "Reading attempt on idle timerfd.\n"); + return; + } + + if (!(our_timer = ao2_find(timerfd_timers, &find_helper, OBJ_POINTER))) { + ast_log(LOG_ERROR, "Couldn't find timer with handle %d\n", handle); + return; + } + + ao2_lock(our_timer); + do { read_result = read(handle, &expirations, sizeof(expirations)); if (read_result == -1) { @@ -174,6 +195,9 @@ } } while (read_result != sizeof(expirations)); + ao2_unlock(our_timer); + ao2_ref(our_timer, -1); + if (expirations != quantity) { ast_debug(2, "Expected to acknowledge %u ticks but got %llu instead\n", quantity, (unsigned long long) expirations); }