workqueue.h 2.6 KB

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