Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 1 | #ifndef _THRIFT_CONCURRENCY_MUTEX_H_ |
2 | #define _THRIFT_CONCURRENCY_MUTEX_H_ 1 | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 3 | |
4 | namespace facebook { namespace thrift { namespace concurrency { | ||||
5 | |||||
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 6 | /** |
7 | * A simple mutex class | ||||
8 | * | ||||
9 | * @author marc | ||||
10 | * @version $Id:$ | ||||
11 | */ | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 12 | class Mutex { |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 13 | public: |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 14 | Mutex(); |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 15 | virtual ~Mutex() {} |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 16 | virtual void lock() const; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 17 | virtual void unlock() const; |
18 | |||||
19 | private: | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 20 | class impl; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 21 | impl* _impl; |
22 | }; | ||||
23 | |||||
24 | class MutexMonitor { | ||||
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 25 | public: |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 26 | MutexMonitor(const Mutex& value) : _mutex(value) { |
27 | _mutex.lock(); | ||||
28 | } | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 29 | ~MutexMonitor() { |
30 | _mutex.unlock(); | ||||
31 | } | ||||
32 | |||||
33 | private: | ||||
34 | const Mutex& _mutex; | ||||
35 | }; | ||||
36 | |||||
37 | |||||
38 | }}} // facebook::thrift::concurrency | ||||
39 | |||||
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 40 | #endif // #ifndef _THRIFT_CONCURRENCY_MUTEX_H_ |