From 2d02ec653355e4f558bd3bb2ef0e442520de26f9 Mon Sep 17 00:00:00 2001 From: Bradley Grainger Date: Mon, 16 Jun 2014 15:41:46 -0700 Subject: [PATCH] Add separate Read/WriteUnlock methods in MutexRW. 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 | 2 +- port/port_posix.cc | 4 +++- port/port_posix.h | 3 ++- util/mutexlock.h | 4 ++-- util/vectorrep.cc | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/db/memtable.cc b/db/memtable.cc index c6b915b99..1dd9dc0ca 100644 --- a/db/memtable.cc +++ b/db/memtable.cc @@ -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; diff --git a/port/port_posix.cc b/port/port_posix.cc index 911cebdf2..2ad10f58f 100644 --- a/port/port_posix.cc +++ b/port/port_posix.cc @@ -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)); diff --git a/port/port_posix.h b/port/port_posix.h index f048d54ce..c2070c7cb 100644 --- a/port/port_posix.h +++ b/port/port_posix.h @@ -120,7 +120,8 @@ class RWMutex { void ReadLock(); void WriteLock(); - void Unlock(); + void ReadUnlock(); + void WriteUnlock(); void AssertHeld() { } private: diff --git a/util/mutexlock.h b/util/mutexlock.h index 0f4e5c8b7..6121ec1ec 100644 --- a/util/mutexlock.h +++ b/util/mutexlock.h @@ -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_; diff --git a/util/vectorrep.cc b/util/vectorrep.cc index cf8bad5c4..0fa10a50f 100644 --- a/util/vectorrep.cc +++ b/util/vectorrep.cc @@ -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()) {