]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Add separate Read/WriteUnlock methods in MutexRW.
authorBradley Grainger <bgrainger@gmail.com>
Mon, 16 Jun 2014 22:41:46 +0000 (15:41 -0700)
committerBradley Grainger <bgrainger@gmail.com>
Mon, 16 Jun 2014 22:41:46 +0000 (15:41 -0700)
Some platforms, particularly Windows, do not have a single method that can
release both a held reader lock and a held writer lock; instead, a
separate method (ReleaseSRWLockShared or ReleaseSRWLockExclusive) must be
called in each case.

This may also be necessary to back MutexRW with a shared_mutex in C++14;
the current language proposal includes both an unlock() and a
shared_unlock() method.

db/memtable.cc
port/port_posix.cc
port/port_posix.h
util/mutexlock.h
util/vectorrep.cc

index c6b915b9979799d363a8139552c69accf2b86ba9..1dd9dc0ca72fc864bdec4ec84bc67fa05341e95c 100644 (file)
@@ -366,7 +366,7 @@ static bool SaveValue(void* arg, const char* entry) {
           s->value->assign(v.data(), v.size());
         }
         if (s->inplace_update_support) {
-          s->mem->GetLock(s->key->user_key())->Unlock();
+          s->mem->GetLock(s->key->user_key())->ReadUnlock();
         }
         *(s->found_final_value) = true;
         return false;
index 911cebdf2deb0cfc437d6e4834d863119bf3c075..2ad10f58f4f20f758c0236e3866f2b46d28d9e8d 100644 (file)
@@ -99,7 +99,9 @@ void RWMutex::ReadLock() { PthreadCall("read lock", pthread_rwlock_rdlock(&mu_))
 
 void RWMutex::WriteLock() { PthreadCall("write lock", pthread_rwlock_wrlock(&mu_)); }
 
-void RWMutex::Unlock() { PthreadCall("unlock", pthread_rwlock_unlock(&mu_)); }
+void RWMutex::ReadUnlock() { PthreadCall("read unlock", pthread_rwlock_unlock(&mu_)); }
+
+void RWMutex::WriteUnlock() { PthreadCall("write unlock", pthread_rwlock_unlock(&mu_)); }
 
 void InitOnce(OnceType* once, void (*initializer)()) {
   PthreadCall("once", pthread_once(once, initializer));
index f048d54ce4117f8dbb507a68441f38404646dd57..c2070c7cbb7bfe67b75589cf152c74e22aaea207 100644 (file)
@@ -120,7 +120,8 @@ class RWMutex {
 
   void ReadLock();
   void WriteLock();
-  void Unlock();
+  void ReadUnlock();
+  void WriteUnlock();
   void AssertHeld() { }
 
  private:
index 0f4e5c8b7b9e31526cbc9bb51a1415cb5f702c06..6121ec1ec7a6279cd97f5b5799bcaa138cd84287 100644 (file)
@@ -46,7 +46,7 @@ class ReadLock {
   explicit ReadLock(port::RWMutex *mu) : mu_(mu) {
     this->mu_->ReadLock();
   }
-  ~ReadLock() { this->mu_->Unlock(); }
+  ~ReadLock() { this->mu_->ReadUnlock(); }
 
  private:
   port::RWMutex *const mu_;
@@ -66,7 +66,7 @@ class WriteLock {
   explicit WriteLock(port::RWMutex *mu) : mu_(mu) {
     this->mu_->WriteLock();
   }
-  ~WriteLock() { this->mu_->Unlock(); }
+  ~WriteLock() { this->mu_->WriteUnlock(); }
 
  private:
   port::RWMutex *const mu_;
index cf8bad5c4d48b0e120bda370e271d9d744f785f3..0fa10a50fc0b6c6f084f0071302005f792656acc 100644 (file)
@@ -252,7 +252,7 @@ void VectorRep::Get(const LookupKey& k, void* callback_args,
     bucket.reset(new Bucket(*bucket_));  // make a copy
   }
   VectorRep::Iterator iter(vector_rep, immutable_ ? bucket_ : bucket, compare_);
-  rwlock_.Unlock();
+  rwlock_.ReadUnlock();
 
   for (iter.Seek(k.user_key(), k.memtable_key().data());
        iter.Valid() && callback_func(callback_args, iter.key()); iter.Next()) {