Ice 3.7 C++11 API Reference
Loading...
Searching...
No Matches
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>
12
13namespace IceUtil
14{
15
16//
17// Forward declarations for friend.
18//
19class Cond;
20
21//
22// Recursive Mutex implementation.
23//
25{
26public:
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
64private:
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
#define ICE_API
Definition Config.h:197
Definition Cond.h:53
Definition Lock.h:37
RecMutex(const MutexProtocol)
friend class Cond
Definition RecMutex.h:94
LockT< RecMutex > Lock
Definition RecMutex.h:31
bool tryLock() const
TryLockT< RecMutex > TryLock
Definition RecMutex.h:32
void lock() const
void unlock() const
bool willUnlock() const
Definition Lock.h:118
Definition Optional.h:1095
MutexProtocol
Definition MutexProtocol.h:14