X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fworkqueue.h;h=b16a9947c31dbd9385a3e5ba5efaaae7a0a45cbe;hb=baa9f9a3368c8d318b9711340727f822d8fc8a34;hp=c16904abc2c694b0d53cb56c408363befc5bbd23;hpb=e6b2a1b6b54dd9bf49f47431769225028dc8aa8d;p=libucw.git diff --git a/lib/workqueue.h b/lib/workqueue.h index c16904ab..b16a9947 100644 --- a/lib/workqueue.h +++ b/lib/workqueue.h @@ -18,6 +18,10 @@ * thread pool, it remembers running requests and gathers replies. A single work queue * should not be used by multiple threads simultaneously. * + * Requests can have priorities. Requests with the highest priority are served first. + * Requests of priority 0 are guaranteed to be served on first-come-first-served + * basis, requests of higher priorities are unordered. + * * When a thread pool is initialized, new_thread() is called for every thread first, * allocating struct worker_thread (and user-defined thread context following it) for * each thread. Then the threads are fired and each of them executes the init_thread() @@ -40,7 +44,9 @@ struct worker_thread { // One of threads serving requests struct raw_queue { // Generic queue with locking pthread_mutex_t queue_mutex; - clist queue; + clist pri0_queue; // Ordinary queue for requests with priority=0 + struct work **pri_heap; // A heap for request with priority>0 + uns heap_cnt, heap_max; sem_t *queue_sem; // Number of requests queued }; @@ -64,9 +70,9 @@ struct work_queue { struct work { // A single request cnode n; + uns priority; struct work_queue *reply_to; // Where to queue the request when it's finished void (*go)(struct worker_thread *t, struct work *w); // Called inside the worker thread - void (*returned)(struct work_queue *q, struct work *w); // Called when returned back, NULL if work_wait should return }; void worker_pool_init(struct worker_pool *p);