Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame^] | 1 | #if !defined(_concurrency_mutex_h_) |
| 2 | #define _concurrency_mutex_h_ 1 |
| 3 | |
| 4 | namespace facebook { namespace thrift { namespace concurrency { |
| 5 | |
| 6 | class Mutex { |
| 7 | |
| 8 | public: |
| 9 | |
| 10 | Mutex(); |
| 11 | |
| 12 | virtual ~Mutex() {} |
| 13 | |
| 14 | virtual void lock() const; |
| 15 | |
| 16 | virtual void unlock() const; |
| 17 | |
| 18 | private: |
| 19 | |
| 20 | class impl; |
| 21 | |
| 22 | impl* _impl; |
| 23 | }; |
| 24 | |
| 25 | class MutexMonitor { |
| 26 | public: |
| 27 | |
| 28 | MutexMonitor(const Mutex& value) : _mutex(value) { |
| 29 | _mutex.lock(); |
| 30 | } |
| 31 | |
| 32 | ~MutexMonitor() { |
| 33 | _mutex.unlock(); |
| 34 | } |
| 35 | |
| 36 | private: |
| 37 | const Mutex& _mutex; |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | }}} // facebook::thrift::concurrency |
| 42 | |
| 43 | #endif // !defined(_concurrency_mutex_h_) |