# HG changeset patch # User John Tsiombikas # Date 1392137220 -7200 # Node ID 2b8281a146af8125325b0dc89d9a2742b2bfc52e # Parent 2fcd1fbb0d1879df8767955fe92cecb0937d4dd9 added debugging crap in the threadpool diff -r 2fcd1fbb0d18 -r 2b8281a146af src/threadpool.c --- a/src/threadpool.c Mon Feb 10 12:11:02 2014 +0200 +++ b/src/threadpool.c Tue Feb 11 18:47:00 2014 +0200 @@ -5,6 +5,7 @@ #include "threadpool.h" struct work_item { + int id; /* just for debugging messages */ void *data; struct work_item *next; }; @@ -106,6 +107,7 @@ int tpool_add_work(struct thread_pool *tpool, void *data) { struct work_item *node; + static int jcounter; if(!(node = alloc_node())) { fprintf(stderr, "%s: failed to allocate new work item node\n", __FUNCTION__); @@ -115,6 +117,9 @@ node->next = 0; pthread_mutex_lock(&tpool->work_lock); + node->id = jcounter++; + + printf("TPOOL: adding work item: %d\n", node->id); if(!tpool->work_list) { tpool->work_list = tpool->work_list_tail = node; @@ -132,8 +137,17 @@ static void *thread_func(void *tp) { + int i, tidx = -1; struct work_item *job; struct thread_pool *tpool = tp; + pthread_t tid = pthread_self(); + + for(i=0; inum_workers; i++) { + if(tpool[i].workers[i] == tid) { + tidx = i; + break; + } + } pthread_mutex_lock(&tpool->work_lock); for(;;) { @@ -143,11 +157,14 @@ continue; /* spurious wakeup, go back to sleep */ } + printf("TPOOL: worker %d start job: %d\n", tidx, job->id); + job = tpool->work_list; tpool->work_list = tpool->work_list->next; tpool->work_func(job->data, tpool->cls); + printf("TPOOL: worker %d completed job: %d\n", tidx, job->id); free_node(job); } pthread_mutex_unlock(&tpool->work_lock);