Tor 0.4.9.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. */
16typedef struct replyqueue_t replyqueue_t;
17/** A thread-pool manages starting threads and passing work to them. */
18typedef 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: */
24typedef 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. */
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);
55void *workqueue_entry_cancel(workqueue_entry_t *pending_work);
56threadpool_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
63replyqueue_t *replyqueue_new(uint32_t alertsocks_flags);
65
67 void (*cb)(threadpool_t *tp));
69
70#endif /* !defined(TOR_WORKQUEUE_H) */
Definition: workqueue.c:98
Integer definitions used throughout Tor.
replyqueue_t * threadpool_get_replyqueue(threadpool_t *tp)
Definition: workqueue.c:579
void replyqueue_process(replyqueue_t *queue)
Definition: workqueue.c:650
void * workqueue_entry_cancel(workqueue_entry_t *pending_work)
Definition: workqueue.c:194
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:389
workqueue_entry_t * threadpool_queue_work(threadpool_t *pool, workqueue_reply_t(*fn)(void *, void *), void(*reply_fn)(void *), void *arg)
Definition: workqueue.c:416
replyqueue_t * replyqueue_new(uint32_t alertsocks_flags)
Definition: workqueue.c:589
int threadpool_register_reply_event(threadpool_t *tp, void(*cb)(threadpool_t *tp))
Definition: workqueue.c:626
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:440
workqueue_reply_t
Definition: workqueue.h:24
@ WQ_RPL_ERROR
Definition: workqueue.h:26
@ WQ_RPL_SHUTDOWN
Definition: workqueue.h:27
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:544
unsigned int threadpool_get_n_threads(threadpool_t *tp)
Definition: workqueue.c:681
workqueue_priority_t
Definition: workqueue.h:31