]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/waitq.h
ebl add sql_escape to catalog messages
[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    Copyright (C) 2001-2006 Kern Sibbald
15
16    This program is free software; you can redistribute it and/or
17    modify it under the terms of the GNU General Public License
18    version 2 as amended with additional clauses defined in the
19    file LICENSE in the main source directory.
20
21    This program is distributed in the hope that it will be useful,
22    but WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
24    the file LICENSE for additional details.
25
26  */
27
28 #ifndef __WAITQ_H
29 #define __WAITQ_H 1
30
31 /*
32  * Structure to keep track of wait queue request
33  */
34 typedef struct waitq_ele_tag {
35    struct waitq_ele_tag *next;
36    int               done_flag;       /* predicate for wait */
37    pthread_cont_t    done;            /* wait for completion */
38    void             *msg;             /* message to be passed */
39 } waitq_ele_t;
40
41 /*
42  * Structure describing a wait queue
43  */
44 typedef struct workq_tag {
45    pthread_mutex_t   mutex;           /* queue access control */
46    pthread_cond_t    wait_req;        /* wait for OK */
47    int               num_msgs;        /* number of waiters */
48    waitq_ele_t       *first;          /* wait queue first item */
49    waitq_ele_t       *last;           /* wait queue last item */
50 } workq_t;
51
52 extern int waitq_init(waitq_t *wq);
53 extern int waitq_destroy(waitq_t *wq);
54 extern int waitq_add(waitq_t *wq, void *msg);
55
56 #endif /* __WAITQ_H */