blob: 9eceb49d18309f7c34d6a2ba6c46766d8de2dd9e [file] [log] [blame]
Mark Sleef5f2be42006-09-05 21:05:31 +00001#ifndef _THRIFT_CONCURRENCY_MUTEX_H_
2#define _THRIFT_CONCURRENCY_MUTEX_H_ 1
Marc Slemko66949872006-07-15 01:52:39 +00003
4namespace facebook { namespace thrift { namespace concurrency {
5
Mark Sleef5f2be42006-09-05 21:05:31 +00006/**
7 * A simple mutex class
8 *
9 * @author marc
10 * @version $Id:$
11 */
Marc Slemko66949872006-07-15 01:52:39 +000012class Mutex {
Marc Slemko66949872006-07-15 01:52:39 +000013 public:
Marc Slemko66949872006-07-15 01:52:39 +000014 Mutex();
Marc Slemko66949872006-07-15 01:52:39 +000015 virtual ~Mutex() {}
Marc Slemko66949872006-07-15 01:52:39 +000016 virtual void lock() const;
Marc Slemko66949872006-07-15 01:52:39 +000017 virtual void unlock() const;
18
19 private:
Marc Slemko66949872006-07-15 01:52:39 +000020 class impl;
Marc Slemko66949872006-07-15 01:52:39 +000021 impl* _impl;
22};
23
24class MutexMonitor {
Mark Sleef5f2be42006-09-05 21:05:31 +000025 public:
Marc Slemko66949872006-07-15 01:52:39 +000026 MutexMonitor(const Mutex& value) : _mutex(value) {
27 _mutex.lock();
28 }
Marc Slemko66949872006-07-15 01:52:39 +000029 ~MutexMonitor() {
30 _mutex.unlock();
31 }
32
33 private:
34 const Mutex& _mutex;
35};
36
37
38}}} // facebook::thrift::concurrency
39
Mark Sleef5f2be42006-09-05 21:05:31 +000040#endif // #ifndef _THRIFT_CONCURRENCY_MUTEX_H_