summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2009-01-16 02:26:50 +0000
committererdgeist <>2009-01-16 02:26:50 +0000
commitf12fa4c36216e83246767a3cff8dbc86e7d7c6eb (patch)
tree989508ccc92346c03ccc02d55a84344165c2ad8b
parent66c906d5d3c100e5fe1e6f088bd1ea17c5831894 (diff)
Use a self pipe to wake from io_wait when a thread finished his work.
-rw-r--r--opentracker.c12
-rw-r--r--ot_mutex.c7
-rw-r--r--trackerlogic.h2
3 files changed, 20 insertions, 1 deletions
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;
38char * g_redirecturl = NULL; 38char * g_redirecturl = NULL;
39uint32_t g_tracker_id; 39uint32_t g_tracker_id;
40volatile int g_opentracker_running = 1; 40volatile int g_opentracker_running = 1;
41int g_self_pipe[2];
41 42
42static char * g_serverdir = NULL; 43static char * g_serverdir = NULL;
43 44
@@ -216,6 +217,8 @@ static void server_mainloop( ) {
216 handle_accept( sock ); 217 handle_accept( sock );
217 else if( (intptr_t)cookie == FLAG_UDP ) 218 else if( (intptr_t)cookie == FLAG_UDP )
218 handle_udp6( sock, &ws ); 219 handle_udp6( sock, &ws );
220 else if( (intptr_t)cookie == FLAG_SELFPIPE ) { printf( "woke up\n" );
221 io_tryread( sock, ws.inbuf, G_INBUF_SIZE ); }
219 else 222 else
220 handle_read( sock, &ws ); 223 handle_read( sock, &ws );
221 } 224 }
@@ -500,6 +503,15 @@ while( scanon ) {
500 503
501 g_now_seconds = time( NULL ); 504 g_now_seconds = time( NULL );
502 505
506 /* Create our self pipe which allows us to interrupt mainloops
507 io_wait in case some data is available to send out */
508 if( pipe( g_self_pipe ) == -1 )
509 panic( "selfpipe failed: " );
510 if( !io_fd( g_self_pipe[0] ) )
511 panic( "selfpipe io_fd failed: " );
512 io_setcookie( g_self_pipe[0], (void*)FLAG_SELFPIPE );
513 io_wantread( g_self_pipe[0] );
514
503 /* Init all sub systems. This call may fail with an exit() */ 515 /* Init all sub systems. This call may fail with an exit() */
504 trackerlogic_init( ); 516 trackerlogic_init( );
505 517
diff --git a/ot_mutex.c b/ot_mutex.c
index 2ed5e81..0127721 100644
--- a/ot_mutex.c
+++ b/ot_mutex.c
@@ -32,6 +32,9 @@ static int bucket_locklist_count = 0;
32static pthread_mutex_t bucket_mutex; 32static pthread_mutex_t bucket_mutex;
33static pthread_cond_t bucket_being_unlocked; 33static pthread_cond_t bucket_being_unlocked;
34 34
35/* Self pipe from opentracker.c */
36extern int g_self_pipe[2];
37
35static int bucket_check( int bucket ) { 38static int bucket_check( int bucket ) {
36 /* C should come with auto-i ;) */ 39 /* C should come with auto-i ;) */
37 int i; 40 int i;
@@ -255,6 +258,8 @@ void mutex_workqueue_pushsuccess( ot_taskid taskid ) {
255 258
256int mutex_workqueue_pushresult( ot_taskid taskid, int iovec_entries, struct iovec *iovec ) { 259int mutex_workqueue_pushresult( ot_taskid taskid, int iovec_entries, struct iovec *iovec ) {
257 struct ot_task * task; 260 struct ot_task * task;
261 const char byte = 'o';
262
258 /* Want exclusive access to tasklist */ 263 /* Want exclusive access to tasklist */
259 MTX_DBG( "pushresult locks.\n" ); 264 MTX_DBG( "pushresult locks.\n" );
260 pthread_mutex_lock( &tasklist_mutex ); 265 pthread_mutex_lock( &tasklist_mutex );
@@ -275,6 +280,8 @@ int mutex_workqueue_pushresult( ot_taskid taskid, int iovec_entries, struct iove
275 pthread_mutex_unlock( &tasklist_mutex ); 280 pthread_mutex_unlock( &tasklist_mutex );
276 MTX_DBG( "pushresult unlocked.\n" ); 281 MTX_DBG( "pushresult unlocked.\n" );
277 282
283 io_trywrite( g_self_pipe[1], &byte, 1 );
284
278 /* Indicate whether the worker has to throw away results */ 285 /* Indicate whether the worker has to throw away results */
279 return task ? 0 : -1; 286 return task ? 0 : -1;
280} 287}
diff --git a/trackerlogic.h b/trackerlogic.h
index 42cecb3..3857202 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -56,7 +56,7 @@ extern volatile int g_opentracker_running;
56#define g_now_minutes (g_now_seconds/60) 56#define g_now_minutes (g_now_seconds/60)
57 57
58extern uint32_t g_tracker_id; 58extern uint32_t g_tracker_id;
59typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA } PROTO_FLAG; 59typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA, FLAG_SELFPIPE } PROTO_FLAG;
60 60
61typedef struct { 61typedef struct {
62 uint8_t data[OT_IP_SIZE+2+2]; 62 uint8_t data[OT_IP_SIZE+2+2];