1 /* Simple threaded work queue using POSIX threads.
2  */
3 #ifndef eslWORKQUEUE_INCLUDED
4 #define eslWORKQUEUE_INCLUDED
5 #include "esl_config.h"
6 
7 typedef struct {
8   pthread_mutex_t  queueMutex;          /* mutex for queue serialization                           */
9   pthread_cond_t   readerQueueCond;     /* condition variable used to wake up the producer         */
10   pthread_cond_t   workerQueueCond;     /* condition variable used to wake up the consumers        */
11 
12   void           **readerQueue;         /* list of objects the the workers have completed          */
13   int              readerQueueCnt;      /* number of objects in the queue                          */
14   int              readerQueueHead;     /* first object in the queue                               */
15 
16   void           **workerQueue;         /* list of objects ready to be processed by worker threads */
17   int              workerQueueCnt;      /* number of objects in the queue                          */
18   int              workerQueueHead;     /* first object in the queue                               */
19 
20   int              queueSize;           /* max number of items a queue will hold                   */
21   int              pendingWorkers;      /* number of consumers waiting for work                    */
22 } ESL_WORK_QUEUE;
23 
24 extern ESL_WORK_QUEUE *esl_workqueue_Create(int size);
25 extern void            esl_workqueue_Destroy(ESL_WORK_QUEUE *queue);
26 
27 extern int esl_workqueue_Init    (ESL_WORK_QUEUE *queue, void *ptr);
28 extern int esl_workqueue_Complete(ESL_WORK_QUEUE *queue);
29 extern int esl_workqueue_Reset   (ESL_WORK_QUEUE *queue);
30 
31 extern int esl_workqueue_Remove(ESL_WORK_QUEUE *queue, void **obj);
32 
33 extern int esl_workqueue_ReaderUpdate(ESL_WORK_QUEUE *queue, void *in, void **out);
34 extern int esl_workqueue_WorkerUpdate(ESL_WORK_QUEUE *queue, void *in, void **out);
35 
36 extern int esl_workqueue_Dump(ESL_WORK_QUEUE *queue);
37 
38 #endif /*eslWORKQUEUE_INCLUDED*/
39 
40