summaryrefslogtreecommitdiff
path: root/src/common/workqueue.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-07-12 11:47:01 -0400
committerNick Mathewson <nickm@torproject.org>2017-07-27 16:28:05 -0400
commit10e0bff4caba483d971d2a4718a40f62530a66ed (patch)
treed0e8151c7d92177a2cf5050c2667b0a0ac300a7a /src/common/workqueue.h
parent5636b160d42e344f936f881992c19b3c27f60a2c (diff)
downloadtor-10e0bff4caba483d971d2a4718a40f62530a66ed.tar.gz
tor-10e0bff4caba483d971d2a4718a40f62530a66ed.zip
Add support for multi-priority workqueues
Each piece of queued work now has an associated priority value; each priority goes on a separate queue. With probability (N-1)/N, the workers will take work from the highest priority nonempty queue. Otherwise, they'll look for work in a queue of lower priority. This behavior is meant to prevent starvation for lower-priority tasks.
Diffstat (limited to 'src/common/workqueue.h')
-rw-r--r--src/common/workqueue.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common/workqueue.h b/src/common/workqueue.h
index 7b483eb7ac..d2508f5329 100644
--- a/src/common/workqueue.h
+++ b/src/common/workqueue.h
@@ -22,6 +22,20 @@ typedef enum workqueue_reply_t {
WQ_RPL_SHUTDOWN = 2, /** indicates thread is shutting down */
} workqueue_reply_t;
+/** Possible priorities for work. Lower numeric values are more important. */
+typedef enum workqueue_priority_t {
+ WQ_PRI_HIGH = 0,
+ WQ_PRI_MED = 1,
+ WQ_PRI_LOW = 2,
+} workqueue_priority_t;
+
+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);
+
workqueue_entry_t *threadpool_queue_work(threadpool_t *pool,
workqueue_reply_t (*fn)(void *,
void *),