1 /* Copyright (c) 2013, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #ifndef TOR_WORKQUEUE_H
5 #define TOR_WORKQUEUE_H
9 /** A replyqueue is used to tell the main thread about the outcome of
10 * work that we queued for the the workers. */
11 typedef struct replyqueue_s replyqueue_t
;
12 /** A thread-pool manages starting threads and passing work to them. */
13 typedef struct threadpool_s threadpool_t
;
14 /** A workqueue entry represents a request that has been passed to a thread
16 typedef struct workqueue_entry_s workqueue_entry_t
;
18 /** Possible return value from a work function: */
20 WQ_RPL_REPLY
= 0, /** indicates success */
21 WQ_RPL_ERROR
= 1, /** indicates fatal error */
22 WQ_RPL_SHUTDOWN
= 2, /** indicates thread is shutting down */
25 workqueue_entry_t
*threadpool_queue_work(threadpool_t
*pool
,
26 workqueue_reply_t (*fn
)(void *,
28 void (*reply_fn
)(void *),
31 int threadpool_queue_update(threadpool_t
*pool
,
32 void *(*dup_fn
)(void *),
33 workqueue_reply_t (*fn
)(void *, void *),
34 void (*free_fn
)(void *),
36 void *workqueue_entry_cancel(workqueue_entry_t
*pending_work
);
37 threadpool_t
*threadpool_new(int n_threads
,
38 replyqueue_t
*replyqueue
,
39 void *(*new_thread_state_fn
)(void*),
40 void (*free_thread_state_fn
)(void*),
42 replyqueue_t
*threadpool_get_replyqueue(threadpool_t
*tp
);
44 replyqueue_t
*replyqueue_new(uint32_t alertsocks_flags
);
45 tor_socket_t
replyqueue_get_socket(replyqueue_t
*rq
);
46 void replyqueue_process(replyqueue_t
*queue
);