2 Bacula® - The Network Backup Solution
4 Copyright (C) 2001-2010 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Bacula Thread Read/Write locking code. It permits
30 * multiple readers but only one writer.
32 * Kern Sibbald, January MMI
34 * This code adapted from "Programming with POSIX Threads", by
44 pthread_mutex_t mutex;
45 pthread_cond_t read; /* wait for read */
46 pthread_cond_t write; /* wait for write */
47 pthread_t writer_id; /* writer's thread id */
48 int priority; /* used in deadlock detection */
49 int valid; /* set when valid */
50 int r_active; /* readers active */
51 int w_active; /* writers active */
52 int r_wait; /* readers waiting */
53 int w_wait; /* writers waiting */
54 int reason; /* reason for lock */
55 bool can_steal; /* can the lock be stolen? */
59 devlock(int reason, bool can_steal=false);
61 int init(int priority);
64 int writelock(int reason, bool can_steal=false);
77 #define DEVLOCK_VALID 0xfadbec
79 #define DEVLOCK_INIIALIZER \
80 {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \
81 PTHREAD_COND_INITIALIZER, DEVOCK_VALID, 0, 0, 0, 0}
83 #endif /* __DEVLOCK_H */