all repos — tint2 @ 6c40536d1a0a9935e63c7414384839883a0d4077

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

*fix* make timer non-blocking to fix freezing when a timer is resetted in a callback function



git-svn-id: http://tint2.googlecode.com/svn/trunk@282 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
Andreas.Fink85 Andreas.Fink85@121b4492-b84c-0410-8b4c-0d4edfb3f3cc
commit

6c40536d1a0a9935e63c7414384839883a0d4077

parent

cb9f2f7517044cf9b46ae60eec1398bdf49236c3

2 files changed, 19 insertions(+), 16 deletions(-)

jump to
M src/tint.csrc/tint.c

@@ -709,6 +709,19 @@ }

// 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);

@@ -785,22 +798,6 @@ dnd_message(&e.xclient);

} 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; } }
M src/util/timer.csrc/util/timer.c

@@ -18,6 +18,7 @@

#include <sys/timerfd.h> #include <stdlib.h> #include <unistd.h> +#include <fcntl.h> #include "timer.h"

@@ -38,6 +39,11 @@ struct timer* t = malloc(sizeof(struct timer));

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; }