File tree Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change 4
4
5
5
struct LockImpl
6
6
{
7
+ #ifdef WINDOWS
8
+ CRITICAL_SECTION cs;
9
+
10
+ LockImpl () { InitializeCriticalSection (&cs); }
11
+ ~LockImpl () { DeleteCriticalSection (&cs); }
12
+
13
+ ICF void Lock () { EnterCriticalSection (&cs); }
14
+ ICF void Unlock () { LeaveCriticalSection (&cs); }
15
+ ICF bool TryLock () { return !!TryEnterCriticalSection (&cs); }
16
+ #else
7
17
std::recursive_mutex mutex;
8
- };
9
18
10
- Lock::~Lock ()
11
- {
12
- delete impl;
13
- }
19
+ ICF void Lock () { mutex.lock (); }
20
+ ICF void Unlock () { mutex.unlock (); }
21
+ ICF bool TryLock () { return mutex.try_lock (); }
22
+ #endif
23
+ };
14
24
15
25
#ifdef CONFIG_PROFILE_LOCKS
16
26
static add_profile_portion_callback add_profile_portion = 0 ;
@@ -55,25 +65,27 @@ void Lock::Enter()
55
65
#else
56
66
Lock::Lock () : impl(new LockImpl), lockCounter(0 ) {}
57
67
68
+ Lock::~Lock () { delete impl; }
69
+
58
70
void Lock::Enter ()
59
71
{
60
- impl->mutex . lock ();
72
+ impl->Lock ();
61
73
lockCounter++;
62
74
}
63
75
#endif // CONFIG_PROFILE_LOCKS
64
76
65
77
bool Lock::TryEnter ()
66
78
{
67
- bool locked = impl->mutex . try_lock ();
79
+ const bool locked = impl->TryLock ();
68
80
if (locked)
69
- lockCounter++ ;
81
+ ++lockCounter ;
70
82
return locked;
71
83
}
72
84
73
85
void Lock::Leave ()
74
86
{
75
- impl->mutex . unlock ();
76
- lockCounter-- ;
87
+ impl->Unlock ();
88
+ --lockCounter ;
77
89
}
78
90
79
91
#ifdef DEBUG
You can’t perform that action at this time.
0 commit comments