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 44
55struct LockImpl
66{
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
717 std::recursive_mutex mutex;
8- };
918
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+ };
1424
1525#ifdef CONFIG_PROFILE_LOCKS
1626static add_profile_portion_callback add_profile_portion = 0 ;
@@ -55,25 +65,27 @@ void Lock::Enter()
5565#else
5666Lock::Lock () : impl(new LockImpl), lockCounter(0 ) {}
5767
68+ Lock::~Lock () { delete impl; }
69+
5870void Lock::Enter ()
5971{
60- impl->mutex . lock ();
72+ impl->Lock ();
6173 lockCounter++;
6274}
6375#endif // CONFIG_PROFILE_LOCKS
6476
6577bool Lock::TryEnter ()
6678{
67- bool locked = impl->mutex . try_lock ();
79+ const bool locked = impl->TryLock ();
6880 if (locked)
69- lockCounter++ ;
81+ ++lockCounter ;
7082 return locked;
7183}
7284
7385void Lock::Leave ()
7486{
75- impl->mutex . unlock ();
76- lockCounter-- ;
87+ impl->Unlock ();
88+ --lockCounter ;
7789}
7890
7991#ifdef DEBUG
You can’t perform that action at this time.
0 commit comments