1 /* 2 Bacula(R) - The Network Backup Solution 3 4 Copyright (C) 2000-2020 Kern Sibbald 5 6 The original author of Bacula is Kern Sibbald, with contributions 7 from many others, a complete list can be found in the file AUTHORS. 8 9 You may use this file and others of this release according to the 10 license defined in the LICENSE file, which includes the Affero General 11 Public License, v3.0 ("AGPLv3") and some additional permissions and 12 terms pursuant to its AGPLv3 Section 7. 13 14 This notice must be preserved when any source code is 15 conveyed and/or propagated. 16 17 Bacula(R) is a registered trademark of Kern Sibbald. 18 */ 19 /* 20 * Bacula wait queue routines. Permits waiting for something 21 * to be done. I.e. for operator to mount new volume. 22 * 23 * Kern Sibbald, March MMI 24 * 25 * This code inspired from "Programming with POSIX Threads", by 26 * David R. Butenhof 27 * 28 */ 29 30 #ifndef __WAITQ_H 31 #define __WAITQ_H 1 32 33 /* 34 * Structure to keep track of wait queue request 35 */ 36 typedef struct waitq_ele_tag { 37 struct waitq_ele_tag *next; 38 int done_flag; /* predicate for wait */ 39 pthread_cont_t done; /* wait for completion */ 40 void *msg; /* message to be passed */ 41 } waitq_ele_t; 42 43 /* 44 * Structure describing a wait queue 45 */ 46 typedef struct workq_tag { 47 pthread_mutex_t mutex; /* queue access control */ 48 pthread_cond_t wait_req; /* wait for OK */ 49 int num_msgs; /* number of waiters */ 50 waitq_ele_t *first; /* wait queue first item */ 51 waitq_ele_t *last; /* wait queue last item */ 52 } workq_t; 53 54 extern int waitq_init(waitq_t *wq); 55 extern int waitq_destroy(waitq_t *wq); 56 extern int waitq_add(waitq_t *wq, void *msg); 57 58 #endif /* __WAITQ_H */ 59