aboutsummaryrefslogtreecommitdiff
path: root/src/thread-pool.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-10-11 10:57:46 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:02 +0100
commita22d0dc84c4411ca1b4583ac7857d5301c690f7c (patch)
treeb7639b8813ef6c8f97160fb8d8a8391a27664eea /src/thread-pool.c
parenta7d2cab127719eeef82584664b1abbbee06656c4 (diff)
indexamajig: Use new thread pool
Diffstat (limited to 'src/thread-pool.c')
-rw-r--r--src/thread-pool.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/thread-pool.c b/src/thread-pool.c
index 6705aa18..6228004b 100644
--- a/src/thread-pool.c
+++ b/src/thread-pool.c
@@ -150,6 +150,7 @@ struct task_queue
int *cookies;
void *(*get_task)(void *);
+ void (*finalise)(void *, void *);
void *queue_args;
void (*work)(void *, int);
};
@@ -200,6 +201,9 @@ static void *task_worker(void *pargsv)
pthread_mutex_lock(&q->lock);
q->n_completed++;
q->cookies[mycookie] = 0;
+ if ( q->finalise ) {
+ q->finalise(q, task);
+ }
pthread_mutex_unlock(&q->lock);
} while ( 1 );
@@ -209,7 +213,8 @@ static void *task_worker(void *pargsv)
int run_threads(int n_threads, void (*work)(void *, int),
- void *(*get_task)(void *), void *queue_args, int max)
+ void *(*get_task)(void *), void (*final)(void *, void *),
+ void *queue_args, int max)
{
pthread_t *workers;
int i;
@@ -220,6 +225,7 @@ int run_threads(int n_threads, void (*work)(void *, int),
pthread_mutex_init(&q.lock, NULL);
q.work = work;
q.get_task = get_task;
+ q.finalise = final;
q.queue_args = queue_args;
q.n_started = 0;
q.n_completed = 0;