workqueue.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Copyright (c) 2013-2018, 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 "lib/cc/torint.h"
  10. /** A replyqueue is used to tell the main thread about the outcome of
  11. * work that we queued for the workers. */
  12. typedef struct replyqueue_s replyqueue_t;
  13. /** A thread-pool manages starting threads and passing work to them. */
  14. typedef struct threadpool_s threadpool_t;
  15. /** A workqueue entry represents a request that has been passed to a thread
  16. * pool. */
  17. typedef struct workqueue_entry_s workqueue_entry_t;
  18. /** Possible return value from a work function: */
  19. typedef enum workqueue_reply_t {
  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 */
  23. } workqueue_reply_t;
  24. /** Possible priorities for work. Lower numeric values are more important. */
  25. typedef enum workqueue_priority_t {
  26. WQ_PRI_HIGH = 0,
  27. WQ_PRI_MED = 1,
  28. WQ_PRI_LOW = 2,
  29. } workqueue_priority_t;
  30. workqueue_entry_t *threadpool_queue_work_priority(threadpool_t *pool,
  31. workqueue_priority_t prio,
  32. workqueue_reply_t (*fn)(void *,
  33. void *),
  34. void (*reply_fn)(void *),
  35. void *arg);
  36. workqueue_entry_t *threadpool_queue_work(threadpool_t *pool,
  37. workqueue_reply_t (*fn)(void *,
  38. void *),
  39. void (*reply_fn)(void *),
  40. void *arg);
  41. int threadpool_queue_update(threadpool_t *pool,
  42. void *(*dup_fn)(void *),
  43. workqueue_reply_t (*fn)(void *, void *),
  44. void (*free_fn)(void *),
  45. void *arg);
  46. void *workqueue_entry_cancel(workqueue_entry_t *pending_work);
  47. threadpool_t *threadpool_new(int n_threads,
  48. replyqueue_t *replyqueue,
  49. void *(*new_thread_state_fn)(void*),
  50. void (*free_thread_state_fn)(void*),
  51. void *arg);
  52. replyqueue_t *threadpool_get_replyqueue(threadpool_t *tp);
  53. replyqueue_t *replyqueue_new(uint32_t alertsocks_flags);
  54. void replyqueue_process(replyqueue_t *queue);
  55. struct event_base;
  56. int threadpool_register_reply_event(threadpool_t *tp,
  57. void (*cb)(threadpool_t *tp));
  58. #endif /* !defined(TOR_WORKQUEUE_H) */