2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
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.
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.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Bacula Thread Read/Write locking code. It permits
21 * multiple readers but only one writer.
23 * Kern Sibbald, January MMI
25 * This code adapted from "Programming with POSIX Threads", by
34 pthread_t writer_id; /* id of writer */
35 int reason; /* save reason */
36 int prev_reason; /* previous reason */
42 pthread_mutex_t mutex;
43 pthread_cond_t read; /* wait for read */
44 pthread_cond_t write; /* wait for write */
45 pthread_t writer_id; /* writer's thread id */
46 int priority; /* used in deadlock detection */
47 int valid; /* set when valid */
48 int r_active; /* readers active */
49 int w_active; /* writers active */
50 int r_wait; /* readers waiting */
51 int w_wait; /* writers waiting */
52 int reason; /* reason for lock */
53 int prev_reason; /* previous reason */
54 bool can_take; /* can the lock be taken? */
58 devlock(int reason, bool can_take=false);
60 int init(int init_priority);
62 int take_lock(take_lock_t *hold, int reason);
63 int return_lock(take_lock_t *hold);
64 void new_reason(int nreason) { prev_reason = reason; reason = nreason; };
65 void restore_reason() { reason = prev_reason; prev_reason = 0; };
67 int writelock(int reason, bool can_take=false);
80 #define DEVLOCK_VALID 0xfadbec
82 #define DEVLOCK_INIIALIZER \
83 {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \
84 PTHREAD_COND_INITIALIZER, DEVOCK_VALID, 0, 0, 0, 0}
86 #endif /* __DEVLOCK_H */