]> Dogcows Code - chaz/tint2/commitdiff
*fix* make timer non-blocking to fix freezing when a timer is resetted in a callback...
authorAndreas Fink <andreas.fink85@googlemail.com>
Mon, 30 Nov 2009 15:36:06 +0000 (15:36 +0000)
committerAndreas Fink <andreas.fink85@googlemail.com>
Mon, 30 Nov 2009 15:36:06 +0000 (15:36 +0000)
src/tint.c
src/util/timer.c

index 3be5311d1b67599e686c9fc02a633ddabed94571..ca8f4ffbf7dacdc4a35274d9d6152f181e25d478 100644 (file)
@@ -709,6 +709,19 @@ int main (int argc, char *argv[])
 
                // Wait for X Event or a Timer
                if (pselect(max_fd+1, &fdset, 0, 0, 0, &empty_mask) > 0) {
+                       // we need to iterate over the whole timer list, since fd_set can only be checked with the
+                       // brute force method FD_ISSET for every possible timer
+                       timer_iter = timer_list;
+                       while (timer_iter) {
+                               timer = timer_iter->data;
+                               if (FD_ISSET(timer->id, &fdset)) {
+                                       uint64_t dummy;
+                                       if ( -1  != read(timer->id, &dummy, sizeof(uint64_t)) )
+                                               timer->_callback();
+                               }
+                               timer_iter = timer_iter->next;
+                       }
+
                        while (XPending (server.dsp)) {
                                XNextEvent(server.dsp, &e);
 
@@ -786,22 +799,6 @@ int main (int argc, char *argv[])
                                                break;
                                }
                        }
-
-                       // we need to iterate over the whole timer list, since fd_set can only be checked with the
-                       // brute force method FD_ISSET for every possible timer
-                       timer_iter = timer_list;
-                       while (timer_iter) {
-                               timer = timer_iter->data;
-                               if (FD_ISSET(timer->id, &fdset)) {
-                                       uint64_t dummy;
-//printf("reading from timer->id=%d\n", timer->id);
-                                       read(timer->id, &dummy, sizeof(uint64_t));
-//printf("Callback timer->_callback\n");
-                                       timer->_callback();
-//printf("Timer callback finished\n");
-                               }
-                               timer_iter = timer_iter->next;
-                       }
                }
 
                switch (signal_pending) {
index e218877946dec17bdf0263b47257d8368227b659..48529dc3f22b8731aadfb70b86c9efe8311930c6 100644 (file)
@@ -18,6 +18,7 @@
 #include <sys/timerfd.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include "timer.h"
 
@@ -38,6 +39,11 @@ int install_timer(int value_sec, int value_nsec, int interval_sec, int interval_
        t->id=timer_fd;
        t->_callback = _callback;
        timer_list = g_slist_prepend(timer_list, t);
+
+       int flags = fcntl( timer_fd, F_GETFL, 0 );
+       if( flags != -1 )
+               fcntl( timer_fd, F_SETFL, flags | O_NONBLOCK );
+
        return timer_fd;
 }
 
This page took 0.024353 seconds and 4 git commands to generate.