]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
remove upgrade(), make all Locks moveable
authorbert hubert <bert.hubert@powerdns.com>
Fri, 7 Apr 2017 13:08:42 +0000 (15:08 +0200)
committerbert hubert <bert.hubert@powerdns.com>
Fri, 7 Apr 2017 13:08:42 +0000 (15:08 +0200)
pdns/lock.hh

index 4d2d15467f0e04d3c6a1ebe7c5626ac3198c40ee..4a0c4a1161e789d139ecb820cdd405ace1489d6c 100644 (file)
@@ -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