Skip to content

Commit

Permalink
refactor: use the try_lock result in TryEnter
Browse files Browse the repository at this point in the history
  • Loading branch information
div72 committed Dec 7, 2023
1 parent 9f5ab15 commit a7a6581
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ class SCOPED_LOCKABLE UniqueLock : public Base
bool TryEnter(const char* pszName, const char* pszFile, int nLine)
{
EnterCritical(pszName, pszFile, nLine, (void*)(Base::mutex()), true);
Base::try_lock();
if (!Base::owns_lock())
LeaveCritical();
return Base::owns_lock();
if (Base::try_lock()) {
return true;
}
LeaveCritical();
return false;
}

public:
Expand Down

0 comments on commit a7a6581

Please sign in to comment.