diff --git a/src/sync.h b/src/sync.h --- a/src/sync.h +++ b/src/sync.h @@ -129,7 +129,9 @@ 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(); + if (!Base::owns_lock()) { + LeaveCritical(); + } return Base::owns_lock(); } @@ -238,19 +240,25 @@ public: void Acquire() { - if (fHaveGrant) return; + if (fHaveGrant) { + return; + } sem->wait(); fHaveGrant = true; } void Release() { - if (!fHaveGrant) return; + if (!fHaveGrant) { + return; + } sem->post(); fHaveGrant = false; } bool TryAcquire() { - if (!fHaveGrant && sem->try_wait()) fHaveGrant = true; + if (!fHaveGrant && sem->try_wait()) { + fHaveGrant = true; + } return fHaveGrant; } @@ -265,10 +273,11 @@ explicit CSemaphoreGrant(CSemaphore &sema, bool fTry = false) : sem(&sema), fHaveGrant(false) { - if (fTry) + if (fTry) { TryAcquire(); - else + } else { Acquire(); + } } ~CSemaphoreGrant() { Release(); } diff --git a/src/sync.cpp b/src/sync.cpp --- a/src/sync.cpp +++ b/src/sync.cpp @@ -117,17 +117,22 @@ lockstack->push_back(std::make_pair(c, locklocation)); for (const std::pair &i : (*lockstack)) { - if (i.first == c) break; + if (i.first == c) { + break; + } std::pair p1 = std::make_pair(i.first, c); - if (lockdata.lockorders.count(p1)) continue; + if (lockdata.lockorders.count(p1)) { + continue; + } lockdata.lockorders[p1] = (*lockstack); std::pair p2 = std::make_pair(c, i.first); lockdata.invlockorders.insert(p2); - if (lockdata.lockorders.count(p2)) + if (lockdata.lockorders.count(p2)) { potential_deadlock_detected(p1, lockdata.lockorders[p2], lockdata.lockorders[p1]); + } } } @@ -155,7 +160,9 @@ void AssertLockHeldInternal(const char *pszName, const char *pszFile, int nLine, void *cs) { for (const std::pair &i : *lockstack) { - if (i.first == cs) return; + if (i.first == cs) { + return; + } } fprintf(stderr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s",