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
32 typedef struct s_rwlock_tag {
33 pthread_mutex_t mutex;
34 pthread_cond_t read; /* wait for read */
35 pthread_cond_t write; /* wait for write */
36 pthread_t writer_id; /* writer's thread id */
37 int priority; /* used in deadlock detection */
38 int valid; /* set when valid */
39 int r_active; /* readers active */
40 int w_active; /* writers active */
41 int r_wait; /* readers waiting */
42 int w_wait; /* writers waiting */
45 typedef struct s_rwsteal_tag {
46 pthread_t writer_id; /* writer's thread id */
51 #define RWLOCK_VALID 0xfacade
53 #define RWL_INIIALIZER \
54 {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \
55 PTHREAD_COND_INITIALIZER, RWLOCK_VALID, 0, 0, 0, 0}
57 #define rwl_writelock(x) rwl_writelock_p((x), __FILE__, __LINE__)
60 * read/write lock prototypes
62 extern int rwl_init(brwlock_t *wrlock, int priority=0);
63 extern int rwl_destroy(brwlock_t *rwlock);
64 extern int rwl_readlock(brwlock_t *rwlock);
65 extern int rwl_readtrylock(brwlock_t *rwlock);
66 extern int rwl_readunlock(brwlock_t *rwlock);
67 extern int rwl_writelock_p(brwlock_t *rwlock,
68 const char *file="*unknown*", int line=0);
69 extern int rwl_writetrylock(brwlock_t *rwlock);
70 extern int rwl_writeunlock(brwlock_t *rwlock);
71 extern bool is_rwl_valid(brwlock_t *rwl);
73 #endif /* __RWLOCK_H */