X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fworkqueue.h;h=b16a9947c31dbd9385a3e5ba5efaaae7a0a45cbe;hb=63b7d5c6c89182792601e29326131e6b12321df9;hp=e8c762b21ff0187252a69722f231d6ebde1bf0ed;hpb=d9d5b4d46efdce006fc484a7964dd6351df94396;p=libucw.git diff --git a/lib/workqueue.h b/lib/workqueue.h index e8c762b2..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,6 +70,7 @@ 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 };