]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
freetdm: only notify interrupt waiters if there is not a notification already pending
authorMoises Silva <moy@sangoma.com>
Thu, 2 Sep 2010 16:38:43 +0000 (12:38 -0400)
committerMoises Silva <moy@sangoma.com>
Thu, 2 Sep 2010 16:52:18 +0000 (12:52 -0400)
libs/freetdm/src/ftdm_threadmutex.c

index 79bd28f7d99008f7c30d5ea6a364052b0c5b56e5..56bd49ca1888231a4963ef05f29b3e632594457c 100644 (file)
@@ -376,9 +376,19 @@ FT_DECLARE(ftdm_status_t) ftdm_interrupt_signal(ftdm_interrupt_t *interrupt)
        }
 #else
        int err;
-       if ((err = write(interrupt->writefd, "w", 1)) != 1) {
-               ftdm_log(FTDM_LOG_ERROR, "Failed to signal interrupt: %s\n", errno, strerror(errno));
-               return FTDM_FAIL;
+       struct pollfd testpoll;
+       testpoll.revents = 0;
+       testpoll.events = POLLIN;
+       testpoll.fd = interrupt->readfd;
+       err = poll(&testpoll, 1, 0);
+       if (err == 0 && !(testpoll.revents & POLLIN)) {
+               /* we just try to notify if there is nothing on the read fd already, 
+                * otherwise users that never call interrupt wait eventually will 
+                * eventually have the pipe buffer filled */
+               if ((err = write(interrupt->writefd, "w", 1)) != 1) {
+                       ftdm_log(FTDM_LOG_ERROR, "Failed to signal interrupt: %s\n", errno, strerror(errno));
+                       return FTDM_FAIL;
+               }
        }
 #endif
        return FTDM_SUCCESS;