blob: 620b3406500afd09fd74bd6412f48805682080e6 [file] [log] [blame]
Mark Slee9f0c6512007-02-28 23:58:26 +00001// 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 Sleef5f2be42006-09-05 21:05:31 +00007#ifndef _THRIFT_CONCURRENCY_MUTEX_H_
8#define _THRIFT_CONCURRENCY_MUTEX_H_ 1
Marc Slemko66949872006-07-15 01:52:39 +00009
10namespace facebook { namespace thrift { namespace concurrency {
11
Mark Sleef5f2be42006-09-05 21:05:31 +000012/**
13 * A simple mutex class
14 *
15 * @author marc
16 * @version $Id:$
17 */
Marc Slemko66949872006-07-15 01:52:39 +000018class Mutex {
Marc Slemko66949872006-07-15 01:52:39 +000019 public:
Marc Slemko66949872006-07-15 01:52:39 +000020 Mutex();
Marc Slemko66949872006-07-15 01:52:39 +000021 virtual ~Mutex() {}
Marc Slemko66949872006-07-15 01:52:39 +000022 virtual void lock() const;
Marc Slemko66949872006-07-15 01:52:39 +000023 virtual void unlock() const;
24
25 private:
Marc Slemko66949872006-07-15 01:52:39 +000026 class impl;
Mark Slee2f6404d2006-10-10 01:37:40 +000027 impl* impl_;
Marc Slemko66949872006-07-15 01:52:39 +000028};
29
30class MutexMonitor {
Mark Sleef5f2be42006-09-05 21:05:31 +000031 public:
Mark Slee2f6404d2006-10-10 01:37:40 +000032 MutexMonitor(const Mutex& value) : mutex_(value) {
33 mutex_.lock();
Marc Slemko66949872006-07-15 01:52:39 +000034 }
Marc Slemko66949872006-07-15 01:52:39 +000035 ~MutexMonitor() {
Mark Slee2f6404d2006-10-10 01:37:40 +000036 mutex_.unlock();
Marc Slemko66949872006-07-15 01:52:39 +000037 }
38
39 private:
Mark Slee2f6404d2006-10-10 01:37:40 +000040 const Mutex& mutex_;
Marc Slemko66949872006-07-15 01:52:39 +000041};
42
43
44}}} // facebook::thrift::concurrency
45
Mark Sleef5f2be42006-09-05 21:05:31 +000046#endif // #ifndef _THRIFT_CONCURRENCY_MUTEX_H_