Skip to content

Commit 9ea58fc

Browse files
committed
xrCore/Threading/Lock: Fixed isLocked().
bool isLocked was been not enough for recursive mutex. We need to use integer, so one Leave() would not make isLocked() == false, if there was previous unpaired Enter() call.
1 parent 82e3f09 commit 9ea58fc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/xrCore/Threading/Lock.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class XRCORE_API Lock
2020
{
2121
public:
2222
#ifdef CONFIG_PROFILE_LOCKS
23-
Lock(const char *id) : isLocked(false), id(id) {}
23+
Lock(const char *id) : lockCounter(0), id(id) {}
2424
#else
25-
Lock() : isLocked(false) {}
25+
Lock() : lockCounter(0) {}
2626
#endif
2727

2828
Lock(const Lock &) = delete;
@@ -34,29 +34,29 @@ class XRCORE_API Lock
3434
void Enter()
3535
{
3636
mutex.lock();
37-
isLocked = true;
37+
++lockCounter;
3838
}
3939
#endif
4040

4141
bool TryEnter()
4242
{
4343
bool locked = mutex.try_lock();
4444
if (locked)
45-
isLocked = true;
45+
++lockCounter;
4646
return locked;
4747
}
4848

4949
void Leave()
5050
{
5151
mutex.unlock();
52-
isLocked = false;
52+
--lockCounter;
5353
}
5454

55-
bool IsLocked() const { return isLocked; }
55+
bool IsLocked() const { return lockCounter; }
5656

5757
private:
5858
std::recursive_mutex mutex;
59-
std::atomic_bool isLocked;
59+
std::atomic_int lockCounter;
6060
#ifdef CONFIG_PROFILE_LOCKS
6161
const char *id;
6262
#endif

0 commit comments

Comments
 (0)