workqueue.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (c) 2013-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file workqueue.h
  5. * \brief Header for workqueue.c
  6. **/
  7. #ifndef TOR_WORKQUEUE_H
  8. #define TOR_WORKQUEUE_H
  9. #include <event.h>
  10. #include "lib/cc/torint.h"
  11. /** A replyqueue is used to tell the main thread about the outcome of
  12. * work that we queued for the workers. */
  13. typedef struct replyqueue_s replyqueue_t;
  14. /** A thread-pool manages starting threads and passing work to them. */
  15. typedef struct threadpool_s threadpool_t;
  16. /** A workqueue entry represents a request that has been passed to a thread
  17. * pool. */
  18. typedef struct workqueue_entry_s workqueue_entry_t;
  19. /** Possible return value from a work function: */
  20. typedef enum workqueue_reply_t {
  21. WQ_RPL_REPLY = 0, /** indicates success */
  22. WQ_RPL_ERROR = 1, /** indicates fatal error */
  23. WQ_RPL_SHUTDOWN = 2, /** indicates thread is shutting down */
  24. } workqueue_reply_t;
  25. /** Possible priorities for work. Lower numeric values are more important. */
  26. typedef enum workqueue_priority_t {
  27. WQ_PRI_HIGH = 0,
  28. WQ_PRI_MED = 1,
  29. WQ_PRI_LOW = 2,
  30. } workqueue_priority_t;
  31. workqueue_entry_t *threadpool_queue_work_priority(threadpool_t *pool,
  32. workqueue_priority_t prio,
  33. workqueue_reply_t (*fn)(void *,
  34. void *),
  35. void (*reply_fn)(void *),
  36. replyqueue_t *reply_queue,
  37. void *arg);
  38. workqueue_entry_t *threadpool_queue_work(threadpool_t *pool,
  39. workqueue_reply_t (*fn)(void *,
  40. void *),
  41. void (*reply_fn)(void *),
  42. replyqueue_t *reply_queue,
  43. void *arg);
  44. int threadpool_queue_update(threadpool_t *pool,
  45. void *(*dup_fn)(void *),
  46. workqueue_reply_t (*fn)(void *, void *),
  47. void (*free_fn)(void *),
  48. void *arg);
  49. void *workqueue_entry_cancel(workqueue_entry_t *pending_work);
  50. threadpool_t *threadpool_new(int n_threads,
  51. void *(*new_thread_state_fn)(void*),
  52. void (*free_thread_state_fn)(void*),
  53. void *arg,
  54. int (*thread_spawn_fn)
  55. (void (*func)(void *), void *data));
  56. threadpool_t *replyqueue_get_threadpool(replyqueue_t *rq);
  57. replyqueue_t *replyqueue_new(uint32_t alertsocks_flags, threadpool_t *pool);
  58. void replyqueue_process(replyqueue_t *queue);
  59. int replyqueue_register_reply_event(replyqueue_t *reply_queue,
  60. struct event_base *base);
  61. void threadpool_set_reply_cb(threadpool_t *tp,
  62. void (*cb)(threadpool_t *, replyqueue_t *));
  63. #endif /* !defined(TOR_WORKQUEUE_H) */