]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/workq.h
kes Fix tray-monitor by not requiring a timer interval in bnet_connect()
[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    Bacula® - The Network Backup Solution
14
15    Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
16
17    The main author of Bacula is Kern Sibbald, with contributions from
18    many others, a complete list can be found in the file AUTHORS.
19    This program is Free Software; you can redistribute it and/or
20    modify it under the terms of version two of the GNU General Public
21    License as published by the Free Software Foundation plus additions
22    that are listed in the file LICENSE.
23
24    This program is distributed in the hope that it will be useful, but
25    WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27    General Public License for more details.
28
29    You should have received a copy of the GNU General Public License
30    along with this program; if not, write to the Free Software
31    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32    02110-1301, USA.
33
34    Bacula® is a registered trademark ofJohn Walker.
35    The licensor of Bacula is the Free Software Foundation Europe
36    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
37    Switzerland, email:ftf@fsfeurope.org.
38 */
39
40 #ifndef __WORKQ_H
41 #define __WORKQ_H 1
42
43 /*
44  * Structure to keep track of work queue request
45  */
46 typedef struct workq_ele_tag {
47    struct workq_ele_tag *next;
48    void                 *data;
49 } workq_ele_t;
50
51 /*
52  * Structure describing a work queue
53  */
54 typedef struct workq_tag {
55    pthread_mutex_t   mutex;           /* queue access control */
56    pthread_cond_t    work;            /* wait for work */
57    pthread_attr_t    attr;            /* create detached threads */
58    workq_ele_t       *first, *last;   /* work queue */
59    int               valid;           /* queue initialized */
60    int               quit;            /* workq should quit */
61    int               max_workers;     /* max threads */
62    int               num_workers;     /* current threads */
63    int               idle_workers;    /* idle threads */
64    void             *(*engine)(void *arg); /* user engine */
65 } workq_t;
66
67 #define WORKQ_VALID  0xdec1992
68
69 extern int workq_init(
70               workq_t *wq,
71               int     threads,        /* maximum threads */
72               void   *(*engine)(void *)   /* engine routine */
73                     );
74 extern int workq_destroy(workq_t *wq);
75 extern int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority);
76 extern int workq_remove(workq_t *wq, workq_ele_t *work_item);
77
78 #endif /* __WORKQ_H */