]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/workq.h
Fix copyright + trademark name
[bacula/bacula] / bacula / src / lib / workq.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2001-2009 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Bacula work queue routines. Permits passing work to
30  *  multiple threads.
31  *
32  *  Kern Sibbald, January MMI
33  *
34  *  This code adapted from "Programming with POSIX Threads", by
35  *    David R. Butenhof
36  *
37  *   Version $Id$
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 */