summaryrefslogtreecommitdiff
path: root/ot_mutex.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2009-01-16 02:26:50 +0000
committerDirk Engling <erdgeist@erdgeist.org>2009-01-16 02:26:50 +0000
commit4e7e39dc1c84ee2b5ee93238f5b510ed4652d45b (patch)
tree02339c746c6c20bdc8f26ebec929034178b06a4c /ot_mutex.c
parent0987307ea38f88318d622c1e089ac678d3279358 (diff)
downloadopentracker-4e7e39dc1c84ee2b5ee93238f5b510ed4652d45b.tar.gz
opentracker-4e7e39dc1c84ee2b5ee93238f5b510ed4652d45b.zip
Use a self pipe to wake from io_wait when a thread finished his work.
Diffstat (limited to 'ot_mutex.c')
-rw-r--r--ot_mutex.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ot_mutex.c b/ot_mutex.c
index e465496..5dd5b14 100644
--- a/ot_mutex.c
+++ b/ot_mutex.c
@@ -32,6 +32,9 @@ static int bucket_locklist_count = 0;
static pthread_mutex_t bucket_mutex;
static pthread_cond_t bucket_being_unlocked;
+/* Self pipe from opentracker.c */
+extern int g_self_pipe[2];
+
static int bucket_check( int bucket ) {
/* C should come with auto-i ;) */
int i;
@@ -255,6 +258,8 @@ void mutex_workqueue_pushsuccess( ot_taskid taskid ) {
int mutex_workqueue_pushresult( ot_taskid taskid, int iovec_entries, struct iovec *iovec ) {
struct ot_task * task;
+ const char byte = 'o';
+
/* Want exclusive access to tasklist */
MTX_DBG( "pushresult locks.\n" );
pthread_mutex_lock( &tasklist_mutex );
@@ -275,6 +280,8 @@ int mutex_workqueue_pushresult( ot_taskid taskid, int iovec_entries, struct iove
pthread_mutex_unlock( &tasklist_mutex );
MTX_DBG( "pushresult unlocked.\n" );
+ io_trywrite( g_self_pipe[1], &byte, 1 );
+
/* Indicate whether the worker has to throw away results */
return task ? 0 : -1;
}
@@ -326,4 +333,4 @@ void mutex_deinit( ) {
byte_zero( all_torrents, sizeof( all_torrents ) );
}
-const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.19 $\n";
+const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.20 $\n";