workqueue.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright (c) 2013-2016, 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 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 {
  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. workqueue_entry_t *threadpool_queue_work(threadpool_t *pool,
  21. workqueue_reply_t (*fn)(void *,
  22. void *),
  23. void (*reply_fn)(void *),
  24. void *arg);
  25. int threadpool_queue_update(threadpool_t *pool,
  26. void *(*dup_fn)(void *),
  27. workqueue_reply_t (*fn)(void *, void *),
  28. void (*free_fn)(void *),
  29. void *arg);
  30. void *workqueue_entry_cancel(workqueue_entry_t *pending_work);
  31. threadpool_t *threadpool_new(int n_threads,
  32. replyqueue_t *replyqueue,
  33. void *(*new_thread_state_fn)(void*),
  34. void (*free_thread_state_fn)(void*),
  35. void *arg);
  36. replyqueue_t *threadpool_get_replyqueue(threadpool_t *tp);
  37. replyqueue_t *replyqueue_new(uint32_t alertsocks_flags);
  38. tor_socket_t replyqueue_get_socket(replyqueue_t *rq);
  39. void replyqueue_process(replyqueue_t *queue);
  40. #endif