Skip to content

Commit

Permalink
xrCore/Threading/Lock: Fixed isLocked().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kaffeine committed Nov 15, 2015
1 parent 82e3f09 commit 9ea58fc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/xrCore/Threading/Lock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class XRCORE_API Lock
{
public:
#ifdef CONFIG_PROFILE_LOCKS
Lock(const char *id) : isLocked(false), id(id) {}
Lock(const char *id) : lockCounter(0), id(id) {}
#else
Lock() : isLocked(false) {}
Lock() : lockCounter(0) {}
#endif

Lock(const Lock &) = delete;
Expand All @@ -34,29 +34,29 @@ class XRCORE_API Lock
void Enter()
{
mutex.lock();
isLocked = true;
++lockCounter;
}
#endif

bool TryEnter()
{
bool locked = mutex.try_lock();
if (locked)
isLocked = true;
++lockCounter;
return locked;
}

void Leave()
{
mutex.unlock();
isLocked = false;
--lockCounter;
}

bool IsLocked() const { return isLocked; }
bool IsLocked() const { return lockCounter; }

private:
std::recursive_mutex mutex;
std::atomic_bool isLocked;
std::atomic_int lockCounter;
#ifdef CONFIG_PROFILE_LOCKS
const char *id;
#endif
Expand Down

0 comments on commit 9ea58fc

Please sign in to comment.