From: yunfang Date: Sat, 14 Jul 2007 01:23:05 +0000 (+0000) Subject: [scope lock wrapped for ReadWriteMutex] X-Git-Tag: 0.2.0~1310 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=a36f5db4b323adbcd13cd298ab73eee2be6200f2;p=common%2Fthrift.git [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 --- 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