From d676748c33c20e17564403cae270385314849c06 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Fri, 7 Apr 2017 15:08:42 +0200 Subject: [PATCH] remove upgrade(), make all Locks moveable --- pdns/lock.hh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pdns/lock.hh b/pdns/lock.hh index 4d2d15467f..4a0c4a1161 100644 --- a/pdns/lock.hh +++ b/pdns/lock.hh @@ -105,12 +105,20 @@ public: throw PDNSException("error acquiring rwlock tryrwlock: "+stringerror()); d_havelock=(errno==0); } + + TryWriteLock(TryWriteLock&& rhs) + { + d_lock = rhs.d_lock; + rhs.d_lock=0; + } + + ~TryWriteLock() { if(g_singleThreaded) return; - if(d_havelock) + if(d_havelock && d_lock) // we might be moved pthread_rwlock_unlock(d_lock); } bool gotIt() @@ -141,12 +149,18 @@ public: throw PDNSException("error acquiring rwlock tryrdlock: "+stringerror()); d_havelock=(errno==0); } + TryReadLock(TryReadLock&& rhs) + { + d_lock = rhs.d_lock; + rhs.d_lock=0; + } + ~TryReadLock() { if(g_singleThreaded) return; - if(d_havelock) + if(d_havelock && d_lock) pthread_rwlock_unlock(d_lock); } bool gotIt() @@ -187,14 +201,5 @@ public: } ReadLock(const ReadLock& rhs) = delete; ReadLock& operator=(const ReadLock& rhs) = delete; - - void upgrade() - { - if(g_singleThreaded) - return; - - pthread_rwlock_unlock(d_lock); - pthread_rwlock_wrlock(d_lock); - } }; #endif -- 2.47.2