blob: 13dec185ea52a1ef511c4d4f25aeb03729715d80 [file] [log] [blame]
Marc Slemko0e53ccd2006-07-17 23:51:05 +00001#if !defined(_concurrency_Monitor_h_)
2#define _concurrency_Monitor_h_ 1
Marc Slemko66949872006-07-15 01:52:39 +00003
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
Marc Slemko0e53ccd2006-07-17 23:51:05 +000014 @version $Id:$ */
Marc Slemko66949872006-07-15 01:52:39 +000015
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
Marc Slemko0e53ccd2006-07-17 23:51:05 +000059#endif // !defined(_concurrency_Monitor_h_)