2 Bacula® - The Network Backup Solution
4 Copyright (C) 2001-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 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 Bacula® is a registered trademark of Kern Sibbald.
17 * Bacula Thread Read/Write locking code. It permits
18 * multiple readers but only one writer.
20 * Kern Sibbald, January MMI
22 * 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 bool rwl_is_init(brwlock_t *rwl);
65 extern int rwl_readlock(brwlock_t *rwlock);
66 extern int rwl_readtrylock(brwlock_t *rwlock);
67 extern int rwl_readunlock(brwlock_t *rwlock);
68 extern int rwl_writelock_p(brwlock_t *rwlock,
69 const char *file="*unknown*", int line=0);
70 extern int rwl_writetrylock(brwlock_t *rwlock);
71 extern int rwl_writeunlock(brwlock_t *rwlock);
73 #endif /* __RWLOCK_H */