summaryrefslogtreecommitdiff
path: root/lib/pthreadpool/pthreadpool_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pthreadpool/pthreadpool_sync.c')
-rw-r--r--lib/pthreadpool/pthreadpool_sync.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/pthreadpool/pthreadpool_sync.c b/lib/pthreadpool/pthreadpool_sync.c
index 837abac54d7..48e6a0ddb60 100644
--- a/lib/pthreadpool/pthreadpool_sync.c
+++ b/lib/pthreadpool/pthreadpool_sync.c
@@ -22,6 +22,8 @@
#include "pthreadpool.h"
struct pthreadpool {
+ bool stopped;
+
/*
* Indicate job completion
*/
@@ -45,6 +47,7 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
if (pool == NULL) {
return ENOMEM;
}
+ pool->stopped = false;
pool->signal_fn = signal_fn;
pool->signal_fn_private_data = signal_fn_private_data;
@@ -65,6 +68,10 @@ size_t pthreadpool_queued_jobs(struct pthreadpool *pool)
int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
void (*fn)(void *private_data), void *private_data)
{
+ if (pool->stopped) {
+ return EINVAL;
+ }
+
fn(private_data);
return pool->signal_fn(job_id, fn, private_data,
@@ -77,6 +84,12 @@ size_t pthreadpool_cancel_job(struct pthreadpool *pool, int job_id,
return 0;
}
+int pthreadpool_stop(struct pthreadpool *pool)
+{
+ pool->stopped = true;
+ return 0;
+}
+
int pthreadpool_destroy(struct pthreadpool *pool)
{
free(pool);