2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 PowerDNS.COM BV
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2
7 as published by the Free Software Foundation
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "pdnsexception.hh"
27 extern bool g_singleThreaded;
31 pthread_mutex_t *d_lock;
34 Lock(pthread_mutex_t *lock) : d_lock(lock)
38 if((errno=pthread_mutex_lock(d_lock)))
39 throw PDNSException("error acquiring lock: "+stringerror());
46 pthread_mutex_unlock(d_lock);
52 pthread_rwlock_t *d_lock;
55 WriteLock(pthread_rwlock_t *lock) : d_lock(lock)
60 if((errno=pthread_rwlock_wrlock(d_lock))) {
61 throw PDNSException("error acquiring rwlock wrlock: "+stringerror());
69 pthread_rwlock_unlock(d_lock);
75 pthread_rwlock_t *d_lock;
79 TryWriteLock(pthread_rwlock_t *lock) : d_lock(lock)
81 if(g_singleThreaded) {
87 if((errno=pthread_rwlock_trywrlock(d_lock)) && errno!=EBUSY)
88 throw PDNSException("error acquiring rwlock tryrwlock: "+stringerror());
89 d_havelock=(errno==0);
97 pthread_rwlock_unlock(d_lock);
110 pthread_rwlock_t *d_lock;
114 TryReadLock(pthread_rwlock_t *lock) : d_lock(lock)
116 if(g_singleThreaded) {
121 if((errno=pthread_rwlock_tryrdlock(d_lock)) && errno!=EBUSY)
122 throw PDNSException("error acquiring rwlock tryrdlock: "+stringerror());
123 d_havelock=(errno==0);
131 pthread_rwlock_unlock(d_lock);
145 pthread_rwlock_t *d_lock;
148 ReadLock(pthread_rwlock_t *lock) : d_lock(lock)
153 if((errno=pthread_rwlock_rdlock(d_lock)))
154 throw PDNSException("error acquiring rwlock tryrwlock: "+stringerror());
161 pthread_rwlock_unlock(d_lock);
169 pthread_rwlock_unlock(d_lock);
170 pthread_rwlock_wrlock(d_lock);