Ensure worker threads actually exit when it is time

This includes a small refactoring to use a new enum (workqueue_reply_t)
for the return values instead of just ints.
This commit is contained in:
Sebastian Hahn
2015-08-20 16:48:13 +02:00
committed by Nick Mathewson
parent 2657ea802b
commit 32220d38c0
5 changed files with 33 additions and 25 deletions
+10 -9
View File
@@ -15,21 +15,22 @@ typedef struct threadpool_s threadpool_t;
* pool. */
typedef struct workqueue_entry_s workqueue_entry_t;
/** Possible return value from a work function: indicates success. */
#define WQ_RPL_REPLY 0
/** Possible return value from a work function: indicates fatal error */
#define WQ_RPL_ERROR 1
/** Possible return value from a work function: indicates thread is shutting
* down. */
#define WQ_RPL_SHUTDOWN 2
/** Possible return value from a work function: */
typedef enum {
WQ_RPL_REPLY = 0, /** indicates success */
WQ_RPL_ERROR = 1, /** indicates fatal error */
WQ_RPL_SHUTDOWN = 2, /** indicates thread is shutting down */
} workqueue_reply_t;
workqueue_entry_t *threadpool_queue_work(threadpool_t *pool,
int (*fn)(void *, void *),
workqueue_reply_t (*fn)(void *,
void *),
void (*reply_fn)(void *),
void *arg);
int threadpool_queue_update(threadpool_t *pool,
void *(*dup_fn)(void *),
int (*fn)(void *, void *),
workqueue_reply_t (*fn)(void *, void *),
void (*free_fn)(void *),
void *arg);
void *workqueue_entry_cancel(workqueue_entry_t *pending_work);