From a36f5db4b323adbcd13cd298ab73eee2be6200f2 Mon Sep 17 00:00:00 2001 From: yunfang Date: Sat, 14 Jul 2007 01:23:05 +0000 Subject: [PATCH] [scope lock wrapped for ReadWriteMutex] Summary: scope lock wrapped around ReadWriteMutex. It's like Guard but you can specify to use it as a read or write lock. Reviewed by: boz Test Plan: used it in AdFinder Revertible: yes git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665162 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/concurrency/Mutex.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/cpp/src/concurrency/Mutex.h b/lib/cpp/src/concurrency/Mutex.h index 7945e057..bb2a6066 100644 --- a/lib/cpp/src/concurrency/Mutex.h +++ b/lib/cpp/src/concurrency/Mutex.h @@ -61,6 +61,22 @@ class Guard { const Mutex& mutex_; }; +class RWGuard { + public: + RWGuard(const ReadWriteMutex& value, bool write = 0) : rw_mutex_(value) { + if (write) { + rw_mutex_.acquireWrite(); + } else { + rw_mutex_.acquireRead(); + } + } + ~RWGuard() { + rw_mutex_.release(); + } + private: + const ReadWriteMutex rw_mutex_; +}; + }}} // facebook::thrift::concurrency -- 2.17.1