blob: 82544f12e183d8a0c7ee7f92e70128fccf55cfd2 [file] [log] [blame]
Marc Slemko66949872006-07-15 01:52:39 +00001#if !defined(_concurrency_mutex_h_)
2#define _concurrency_mutex_h_ 1
3
4namespace facebook { namespace thrift { namespace concurrency {
5
6/** A monitor is a combination mutex and condition-event. Waiting and notifying condition events requires that the caller own the mutex. Mutex
7 lock and unlock operations can be performed independently of condition events. This is more or less analogous to java.lang.Object multi-thread
8 operations
9
10 Note that all methods are const. Monitors implement logical constness, not bit constness. This allows const methods to call monitor
11 methods without needing to cast away constness or change to non-const signatures.
12
13 @author marc
14 @version $Id$ */
15
16class Monitor {
17
18 public:
19
20 Monitor();
21
22 virtual ~Monitor();
23
24 virtual void lock() const;
25
26 virtual void unlock() const;
27
28 virtual void wait(long long timeout=0LL) const;
29
30 virtual void notify() const;
31
32 virtual void notifyAll() const;
33
34 private:
35
36 class Impl;
37
38 Impl* _impl;
39};
40
41class Synchronized {
42 public:
43
44 Synchronized(const Monitor& value) : _monitor(value) {
45 _monitor.lock();
46 }
47
48 ~Synchronized() {
49 _monitor.unlock();
50 }
51
52 private:
53 const Monitor& _monitor;
54};
55
56
57}}} // facebook::thrift::concurrency
58
59#endif // !defined(_concurrency_mutex_h_)