Merged revisions 325673 via svnmerge from
authorDavid Vossel <dvossel@digium.com>
Wed, 29 Jun 2011 19:02:19 +0000 (19:02 +0000)
committerDavid Vossel <dvossel@digium.com>
Wed, 29 Jun 2011 19:02:19 +0000 (19:02 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
  r325673 | dvossel | 2011-06-29 13:59:33 -0500 (Wed, 29 Jun 2011) | 6 lines

  Fixes timerfd locking issue.

  (closes ASTERISK-17867, ASTERISK-17415)
  Patches:
       fix uploaded by kobaz
  Review: https://reviewboard.asterisk.org/r/1255/
........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@325674 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_timing_timerfd.c

index ae5d2b4..3e686f8 100644 (file)
@@ -162,7 +162,35 @@ static void timerfd_timer_ack(int handle, unsigned int quantity)
        uint64_t expirations;
        int read_result = 0;
 
+       struct timerfd_timer *our_timer, find_helper = {
+               .handle = handle,
+       };
+
+       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;
+       }
+
+       if (our_timer->saved_timer.it_value.tv_nsec == 0L) {
+               ast_log(LOG_DEBUG, "Reading attempt on idle timerfd.\n");
+               return;
+       }
+
        do {
+               struct itimerspec timer_status;
+
+               if (timerfd_gettime(handle, &timer_status)) {
+                       ast_log(LOG_ERROR, "Call to timerfd_gettime() error: %s\n", strerror(errno));
+                       expirations = 0;
+                       break;
+               }
+
+               if ((timer_status.it_value.tv_sec == 0) && (timer_status.it_value.tv_nsec == 0)) {
+                       ast_log(LOG_DEBUG, "Call to timerfd_timer_ack() with disarmed timer - break now.\n");
+                       expirations = 0;
+                       break;
+               }
+
                read_result = read(handle, &expirations, sizeof(expirations));
                if (read_result == -1) {
                        if (errno == EINTR || errno == EAGAIN) {