Skip to content

Commit

Permalink
Merge pull request #2723 from div72/sync-nodiscard
Browse files Browse the repository at this point in the history
refactor: use the try_lock result in TryEnter
  • Loading branch information
jamescowens authored Dec 10, 2023
2 parents f82e653 + a7a6581 commit f5aa2b1
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 f5aa2b1

Please sign in to comment.