Tor  0.4.7.0-alpha-dev
workqueue.h
Go to the documentation of this file.
1 /* Copyright (c) 2013-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * \file workqueue.h
6  * \brief Header for workqueue.c
7  **/
8 
9 #ifndef TOR_WORKQUEUE_H
10 #define TOR_WORKQUEUE_H
11 
12 #include "lib/cc/torint.h"
13 
14 /** A replyqueue is used to tell the main thread about the outcome of
15  * work that we queued for the workers. */
16 typedef struct replyqueue_t replyqueue_t;
17 /** A thread-pool manages starting threads and passing work to them. */
18 typedef struct threadpool_t threadpool_t;
19 /** A workqueue entry represents a request that has been passed to a thread
20  * pool. */
22 
23 /** Possible return value from a work function: */
24 typedef enum workqueue_reply_t {
25  WQ_RPL_REPLY = 0, /** indicates success */
26  WQ_RPL_ERROR = 1, /** indicates fatal error */
27  WQ_RPL_SHUTDOWN = 2, /** indicates thread is shutting down */
29 
30 /** Possible priorities for work. Lower numeric values are more important. */
31 typedef enum workqueue_priority_t {
32  WQ_PRI_HIGH = 0,
33  WQ_PRI_MED = 1,
34  WQ_PRI_LOW = 2,
36 
39  workqueue_reply_t (*fn)(void *,
40  void *),
41  void (*reply_fn)(void *),
42  void *arg);
43 
45  workqueue_reply_t (*fn)(void *,
46  void *),
47  void (*reply_fn)(void *),
48  void *arg);
49 
51  void *(*dup_fn)(void *),
52  workqueue_reply_t (*fn)(void *, void *),
53  void (*free_fn)(void *),
54  void *arg);
55 void *workqueue_entry_cancel(workqueue_entry_t *pending_work);
56 threadpool_t *threadpool_new(int n_threads,
57  replyqueue_t *replyqueue,
58  void *(*new_thread_state_fn)(void*),
59  void (*free_thread_state_fn)(void*),
60  void *arg);
62 
63 replyqueue_t *replyqueue_new(uint32_t alertsocks_flags);
64 void replyqueue_process(replyqueue_t *queue);
65 
67  void (*cb)(threadpool_t *tp));
68 
69 #endif /* !defined(TOR_WORKQUEUE_H) */
Definition: workqueue.c:95
Integer definitions used throughout Tor.
threadpool_t * threadpool_new(int n_threads, replyqueue_t *replyqueue, void *(*new_thread_state_fn)(void *), void(*free_thread_state_fn)(void *), void *arg)
Definition: workqueue.c:541
void * workqueue_entry_cancel(workqueue_entry_t *pending_work)
Definition: workqueue.c:191
replyqueue_t * threadpool_get_replyqueue(threadpool_t *tp)
Definition: workqueue.c:576
void replyqueue_process(replyqueue_t *queue)
Definition: workqueue.c:647
replyqueue_t * replyqueue_new(uint32_t alertsocks_flags)
Definition: workqueue.c:586
workqueue_entry_t * threadpool_queue_work_priority(threadpool_t *pool, workqueue_priority_t prio, workqueue_reply_t(*fn)(void *, void *), void(*reply_fn)(void *), void *arg)
Definition: workqueue.c:386
int threadpool_register_reply_event(threadpool_t *tp, void(*cb)(threadpool_t *tp))
Definition: workqueue.c:623
int threadpool_queue_update(threadpool_t *pool, void *(*dup_fn)(void *), workqueue_reply_t(*fn)(void *, void *), void(*free_fn)(void *), void *arg)
Definition: workqueue.c:437
workqueue_reply_t
Definition: workqueue.h:24
@ WQ_RPL_ERROR
Definition: workqueue.h:26
@ WQ_RPL_SHUTDOWN
Definition: workqueue.h:27
workqueue_priority_t
Definition: workqueue.h:31
workqueue_entry_t * threadpool_queue_work(threadpool_t *pool, workqueue_reply_t(*fn)(void *, void *), void(*reply_fn)(void *), void *arg)
Definition: workqueue.c:413