Ice 3.7 C++11 API Reference
RecMutex.h
Go to the documentation of this file.
1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_UTIL_RMUTEX_H
6 #define ICE_UTIL_RMUTEX_H
7 
8 #include <IceUtil/Config.h>
9 #include <IceUtil/Lock.h>
11 #include <IceUtil/MutexProtocol.h>
12 
13 namespace IceUtil
14 {
15 
16 //
17 // Forward declarations for friend.
18 //
19 class Cond;
20 
21 //
22 // Recursive Mutex implementation.
23 //
25 {
26 public:
27 
28  //
29  // Lock & TryLock typedefs.
30  //
33 
37 
38  //
39  // Note that lock/tryLock & unlock in general should not be used
40  // directly. Instead use Lock & TryLock.
41  //
42 
43  void lock() const;
44 
45  //
46  // Returns true if the lock was acquired or was already acquired
47  // by the calling thread, and false otherwise.
48  //
49  bool tryLock() const;
50 
51  void unlock() const;
52 
53  //
54  // Returns true if the mutex will unlock when calling unlock()
55  // (false otherwise). For non-recursive mutexes, this will always
56  // return true.
57  // This function is used by the Monitor implementation to know whether
58  // the Mutex has been locked for the first time, or unlocked for the
59  // last time (that is another thread is able to acquire the mutex).
60  // Pre-condition: the mutex must be locked.
61  //
62  bool willUnlock() const;
63 
64 private:
65 
66  void init(const MutexProtocol);
67  // noncopyable
68  RecMutex(const RecMutex&);
69  void operator=(const RecMutex&);
70 
71  //
72  // LockState and the lock/unlock variations are for use by the
73  // Condition variable implementation.
74  //
75 #ifdef _WIN32
76  struct LockState
77  {
78 # ifdef ICE_HAS_WIN32_CONDVAR
79  CRITICAL_SECTION* mutex;
80 # endif
81  int count;
82  };
83 #else
84  struct LockState
85  {
86  pthread_mutex_t* mutex;
87  int count;
88  };
89 #endif
90 
91  void unlock(LockState&) const;
92  void lock(LockState&) const;
93 
94  friend class Cond;
95 
96 #ifdef _WIN32
97  mutable CRITICAL_SECTION _mutex;
98 #else
99  mutable pthread_mutex_t _mutex;
100 #endif
101 
102  mutable int _count;
103 };
104 
105 } // End namespace IceUtil
106 
107 #endif
IceUtil::RecMutex
Definition: RecMutex.h:25
IceUtil::TryLockT
Definition: Lock.h:118
IceUtil::Cond
Definition: Cond.h:53
IceUtil::RecMutex::~RecMutex
~RecMutex()
IceUtil::RecMutex::tryLock
bool tryLock() const
IceUtil::LockT
Definition: Lock.h:37
IceUtil
Definition: Optional.h:1095
ICE_API
#define ICE_API
Definition: Config.h:197
IceUtil::RecMutex::TryLock
TryLockT< RecMutex > TryLock
Definition: RecMutex.h:32
IceUtil::RecMutex::RecMutex
RecMutex()
Lock.h
Config.h
IceUtil::RecMutex::RecMutex
RecMutex(const MutexProtocol)
MutexProtocol.h
IceUtil::RecMutex::Lock
LockT< RecMutex > Lock
Definition: RecMutex.h:31
IceUtil::RecMutex::lock
void lock() const
ThreadException.h
IceUtil::RecMutex::unlock
void unlock() const
IceUtil::MutexProtocol
MutexProtocol
Definition: MutexProtocol.h:14
IceUtil::RecMutex::willUnlock
bool willUnlock() const