From f12fa4c36216e83246767a3cff8dbc86e7d7c6eb Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Fri, 16 Jan 2009 02:26:50 +0000 Subject: Use a self pipe to wake from io_wait when a thread finished his work. --- opentracker.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'opentracker.c') diff --git a/opentracker.c b/opentracker.c index 970995a..8811a6e 100644 --- a/opentracker.c +++ b/opentracker.c @@ -38,6 +38,7 @@ time_t g_now_seconds; char * g_redirecturl = NULL; uint32_t g_tracker_id; volatile int g_opentracker_running = 1; +int g_self_pipe[2]; static char * g_serverdir = NULL; @@ -216,6 +217,8 @@ static void server_mainloop( ) { handle_accept( sock ); else if( (intptr_t)cookie == FLAG_UDP ) handle_udp6( sock, &ws ); + else if( (intptr_t)cookie == FLAG_SELFPIPE ) { printf( "woke up\n" ); + io_tryread( sock, ws.inbuf, G_INBUF_SIZE ); } else handle_read( sock, &ws ); } @@ -500,6 +503,15 @@ while( scanon ) { g_now_seconds = time( NULL ); + /* Create our self pipe which allows us to interrupt mainloops + io_wait in case some data is available to send out */ + if( pipe( g_self_pipe ) == -1 ) + panic( "selfpipe failed: " ); + if( !io_fd( g_self_pipe[0] ) ) + panic( "selfpipe io_fd failed: " ); + io_setcookie( g_self_pipe[0], (void*)FLAG_SELFPIPE ); + io_wantread( g_self_pipe[0] ); + /* Init all sub systems. This call may fail with an exit() */ trackerlogic_init( ); -- cgit v1.2.3