]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/waitq.h
152b66e3af5a90707e3c0a84cabf462383c55db6
[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  */
11 /*
12    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
13
14    This program is free software; you can redistribute it and/or
15    modify it under the terms of the GNU General Public License as
16    published by the Free Software Foundation; either version 2 of
17    the License, or (at your option) any later version.
18
19    This program is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22    General Public License for more details.
23
24    You should have received a copy of the GNU General Public
25    License along with this program; if not, write to the Free
26    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27    MA 02111-1307, USA.
28
29  */
30
31 #ifndef __WAITQ_H 
32 #define __WAITQ_H 1
33
34 /* 
35  * Structure to keep track of wait queue request
36  */
37 typedef struct waitq_ele_tag {
38    struct waitq_ele_tag *next;
39    int               done_flag;       /* predicate for wait */
40    pthread_cont_t    done;            /* wait for completion */
41    void             *msg;             /* message to be passed */
42 } waitq_ele_t;
43
44 /* 
45  * Structure describing a wait queue
46  */
47 typedef struct workq_tag {
48    pthread_mutex_t   mutex;           /* queue access control */
49    pthread_cond_t    wait_req;        /* wait for OK */
50    int               num_msgs;        /* number of waiters */
51    waitq_ele_t       *first;          /* wait queue first item */
52    waitq_ele_t       *last;           /* wait queue last item */
53 } workq_t;
54
55 extern int waitq_init(waitq_t *wq);
56 extern int waitq_destroy(waitq_t *wq);
57 extern int waitq_add(waitq_t *wq, void *msg);
58
59 #endif /* __WAITQ_H */