Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
2 | // Distributed under the Thrift Software License | ||||
3 | // | ||||
4 | // See accompanying file LICENSE or visit the Thrift site at: | ||||
5 | // http://developers.facebook.com/thrift/ | ||||
6 | |||||
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 7 | #ifndef _THRIFT_CONCURRENCY_MUTEX_H_ |
8 | #define _THRIFT_CONCURRENCY_MUTEX_H_ 1 | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 9 | |
10 | namespace facebook { namespace thrift { namespace concurrency { | ||||
11 | |||||
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 12 | /** |
13 | * A simple mutex class | ||||
14 | * | ||||
15 | * @author marc | ||||
16 | * @version $Id:$ | ||||
17 | */ | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 18 | class Mutex { |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 19 | public: |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 20 | Mutex(); |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 21 | virtual ~Mutex() {} |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 22 | virtual void lock() const; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 23 | virtual void unlock() const; |
24 | |||||
25 | private: | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 26 | class impl; |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 27 | impl* impl_; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 28 | }; |
29 | |||||
30 | class MutexMonitor { | ||||
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 31 | public: |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 32 | MutexMonitor(const Mutex& value) : mutex_(value) { |
33 | mutex_.lock(); | ||||
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 34 | } |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 35 | ~MutexMonitor() { |
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 36 | mutex_.unlock(); |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 37 | } |
38 | |||||
39 | private: | ||||
Mark Slee | 2f6404d | 2006-10-10 01:37:40 +0000 | [diff] [blame] | 40 | const Mutex& mutex_; |
Marc Slemko | 6694987 | 2006-07-15 01:52:39 +0000 | [diff] [blame] | 41 | }; |
42 | |||||
43 | |||||
44 | }}} // facebook::thrift::concurrency | ||||
45 | |||||
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 46 | #endif // #ifndef _THRIFT_CONCURRENCY_MUTEX_H_ |