10
10
11
11
#include < boost/thread/condition_variable.hpp>
12
12
#include < boost/thread/mutex.hpp>
13
- #include < boost/thread/recursive_mutex.hpp>
13
+ #include < condition_variable>
14
+ #include < thread>
15
+ #include < mutex>
14
16
15
17
16
18
// //////////////////////////////////////////////
21
23
22
24
/*
23
25
CCriticalSection mutex;
24
- boost ::recursive_mutex mutex;
26
+ std ::recursive_mutex mutex;
25
27
26
28
LOCK(mutex);
27
- boost ::unique_lock<boost ::recursive_mutex> criticalblock(mutex);
29
+ std ::unique_lock<std ::recursive_mutex> criticalblock(mutex);
28
30
29
31
LOCK2(mutex1, mutex2);
30
- boost ::unique_lock<boost ::recursive_mutex> criticalblock1(mutex1);
31
- boost ::unique_lock<boost ::recursive_mutex> criticalblock2(mutex2);
32
+ std ::unique_lock<std ::recursive_mutex> criticalblock1(mutex1);
33
+ std ::unique_lock<std ::recursive_mutex> criticalblock2(mutex2);
32
34
33
35
TRY_LOCK(mutex, name);
34
- boost ::unique_lock<boost ::recursive_mutex> name(mutex, boost ::try_to_lock_t);
36
+ std ::unique_lock<std ::recursive_mutex> name(mutex, std ::try_to_lock_t);
35
37
36
38
ENTER_CRITICAL_SECTION(mutex); // no RAII
37
39
mutex.lock();
@@ -85,33 +87,35 @@ void static inline DeleteLock(void* cs) {}
85
87
#define AssertLockHeld (cs ) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
86
88
87
89
/* *
88
- * Wrapped boost mutex: supports recursive locking, but no waiting
90
+ * Wrapped mutex: supports recursive locking, but no waiting
89
91
* TODO: We should move away from using the recursive lock by default.
90
92
*/
91
- class CCriticalSection : public AnnotatedMixin <boost ::recursive_mutex>
93
+ class CCriticalSection : public AnnotatedMixin <std ::recursive_mutex>
92
94
{
93
95
public:
94
96
~CCriticalSection () {
95
97
DeleteLock ((void *)this );
96
98
}
97
99
};
98
100
99
- /* * Wrapped boost mutex: supports waiting but not recursive locking */
100
- typedef AnnotatedMixin<boost ::mutex> CWaitableCriticalSection;
101
+ /* * Wrapped mutex: supports waiting but not recursive locking */
102
+ typedef AnnotatedMixin<std ::mutex> CWaitableCriticalSection;
101
103
102
- /* * Just a typedef for boost::condition_variable, can be wrapped later if desired */
103
- typedef boost::condition_variable CConditionVariable;
104
+ /* * Just a typedef for std::condition_variable, can be wrapped later if desired */
105
+ typedef std::condition_variable CConditionVariable;
106
+
107
+ /* * Just a typedef for std::unique_lock, can be wrapped later if desired */
108
+ typedef std::unique_lock<std::mutex> WaitableLock;
104
109
105
110
#ifdef DEBUG_LOCKCONTENTION
106
111
void PrintLockContention (const char * pszName, const char * pszFile, int nLine);
107
112
#endif
108
113
109
- /* * Wrapper around boost::unique_lock<Mutex> */
110
- template <typename Mutex>
111
- class SCOPED_LOCKABLE CMutexLock
114
+ /* * Wrapper around std::unique_lock<CCriticalSection> */
115
+ class SCOPED_LOCKABLE CCriticalBlock
112
116
{
113
117
private:
114
- boost ::unique_lock<Mutex > lock;
118
+ std ::unique_lock<CCriticalSection > lock;
115
119
116
120
void Enter (const char * pszName, const char * pszFile, int nLine)
117
121
{
@@ -136,26 +140,26 @@ class SCOPED_LOCKABLE CMutexLock
136
140
}
137
141
138
142
public:
139
- CMutexLock (Mutex & mutexIn, const char * pszName, const char * pszFile, int nLine, bool fTry = false ) EXCLUSIVE_LOCK_FUNCTION (mutexIn) : lock (mutexIn, boost ::defer_lock)
143
+ CCriticalBlock (CCriticalSection & mutexIn, const char * pszName, const char * pszFile, int nLine, bool fTry = false ) EXCLUSIVE_LOCK_FUNCTION (mutexIn) : lock (mutexIn, std ::defer_lock)
140
144
{
141
145
if (fTry )
142
146
TryEnter (pszName, pszFile, nLine);
143
147
else
144
148
Enter (pszName, pszFile, nLine);
145
149
}
146
150
147
- CMutexLock (Mutex * pmutexIn, const char * pszName, const char * pszFile, int nLine, bool fTry = false ) EXCLUSIVE_LOCK_FUNCTION (pmutexIn)
151
+ CCriticalBlock (CCriticalSection * pmutexIn, const char * pszName, const char * pszFile, int nLine, bool fTry = false ) EXCLUSIVE_LOCK_FUNCTION (pmutexIn)
148
152
{
149
153
if (!pmutexIn) return ;
150
154
151
- lock = boost ::unique_lock<Mutex >(*pmutexIn, boost ::defer_lock);
155
+ lock = std ::unique_lock<CCriticalSection >(*pmutexIn, std ::defer_lock);
152
156
if (fTry )
153
157
TryEnter (pszName, pszFile, nLine);
154
158
else
155
159
Enter (pszName, pszFile, nLine);
156
160
}
157
161
158
- ~CMutexLock () UNLOCK_FUNCTION ()
162
+ ~CCriticalBlock () UNLOCK_FUNCTION ()
159
163
{
160
164
if (lock.owns_lock ())
161
165
LeaveCritical ();
@@ -167,8 +171,6 @@ class SCOPED_LOCKABLE CMutexLock
167
171
}
168
172
};
169
173
170
- typedef CMutexLock<CCriticalSection> CCriticalBlock;
171
-
172
174
#define PASTE (x, y ) x ## y
173
175
#define PASTE2 (x, y ) PASTE(x, y)
174
176
0 commit comments