]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/waitq.h
Convert to pure GPL v2 license.
[bacula/bacula] / bacula / src / lib / waitq.h
1 /*
2  * Bacula wait queue routines. Permits waiting for something
3  *   to be done. I.e. for operator to mount new volume.
4  *
5  *  Kern Sibbald, March MMI
6  *
7  *  This code inspired from "Programming with POSIX Threads", by
8  *    David R. Butenhof
9  *
10  *   Version $Id$
11  *
12  */
13 /*
14    Bacula® - The Network Backup Solution
15
16    Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
17
18    The main author of Bacula is Kern Sibbald, with contributions from
19    many others, a complete list can be found in the file AUTHORS.
20    This program is Free Software; you can redistribute it and/or
21    modify it under the terms of version two of the GNU General Public
22    License as published by the Free Software Foundation and included
23    in the file LICENSE.
24
25    This program is distributed in the hope that it will be useful, but
26    WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28    General Public License for more details.
29
30    You should have received a copy of the GNU General Public License
31    along with this program; if not, write to the Free Software
32    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
33    02110-1301, USA.
34
35    Bacula® is a registered trademark ofJohn Walker.
36    The licensor of Bacula is the Free Software Foundation Europe
37    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
38    Switzerland, email:ftf@fsfeurope.org.
39 */
40
41 #ifndef __WAITQ_H
42 #define __WAITQ_H 1
43
44 /*
45  * Structure to keep track of wait queue request
46  */
47 typedef struct waitq_ele_tag {
48    struct waitq_ele_tag *next;
49    int               done_flag;       /* predicate for wait */
50    pthread_cont_t    done;            /* wait for completion */
51    void             *msg;             /* message to be passed */
52 } waitq_ele_t;
53
54 /*
55  * Structure describing a wait queue
56  */
57 typedef struct workq_tag {
58    pthread_mutex_t   mutex;           /* queue access control */
59    pthread_cond_t    wait_req;        /* wait for OK */
60    int               num_msgs;        /* number of waiters */
61    waitq_ele_t       *first;          /* wait queue first item */
62    waitq_ele_t       *last;           /* wait queue last item */
63 } workq_t;
64
65 extern int waitq_init(waitq_t *wq);
66 extern int waitq_destroy(waitq_t *wq);
67 extern int waitq_add(waitq_t *wq, void *msg);
68
69 #endif /* __WAITQ_H */