]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/workq.h
Eliminate dependency on man2html.
[bacula/bacula] / bacula / src / lib / workq.h
1 /*
2  * Bacula work queue routines. Permits passing work to
3  *  multiple threads.
4  *
5  *  Kern Sibbald, January MMI
6  *
7  *  This code adapted from "Programming with POSIX Threads", by
8  *    David R. Butenhof
9  *
10  *   Version $Id$
11  */
12 /*
13    Copyright (C) 2001-2006 Kern Sibbald
14
15    This program is free software; you can redistribute it and/or
16    modify it under the terms of the GNU General Public License
17    version 2 as amended with additional clauses defined in the
18    file LICENSE in the main source directory.
19
20    This program is distributed in the hope that it will be useful,
21    but WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
23    the file LICENSE for additional details.
24
25  */
26
27 #ifndef __WORKQ_H
28 #define __WORKQ_H 1
29
30 /*
31  * Structure to keep track of work queue request
32  */
33 typedef struct workq_ele_tag {
34    struct workq_ele_tag *next;
35    void                 *data;
36 } workq_ele_t;
37
38 /*
39  * Structure describing a work queue
40  */
41 typedef struct workq_tag {
42    pthread_mutex_t   mutex;           /* queue access control */
43    pthread_cond_t    work;            /* wait for work */
44    pthread_attr_t    attr;            /* create detached threads */
45    workq_ele_t       *first, *last;   /* work queue */
46    int               valid;           /* queue initialized */
47    int               quit;            /* workq should quit */
48    int               max_workers;     /* max threads */
49    int               num_workers;     /* current threads */
50    int               idle_workers;    /* idle threads */
51    void             *(*engine)(void *arg); /* user engine */
52 } workq_t;
53
54 #define WORKQ_VALID  0xdec1992
55
56 extern int workq_init(
57               workq_t *wq,
58               int     threads,        /* maximum threads */
59               void   *(*engine)(void *)   /* engine routine */
60                     );
61 extern int workq_destroy(workq_t *wq);
62 extern int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority);
63 extern int workq_remove(workq_t *wq, workq_ele_t *work_item);
64
65 #endif /* __WORKQ_H */