diff --git a/src/sync.cpp b/src/sync.cpp --- a/src/sync.cpp +++ b/src/sync.cpp @@ -71,7 +71,7 @@ std::mutex dd_mutex; } static lockdata; -static thread_local std::unique_ptr lockstack; +static thread_local LockStack g_lockstack; static void potential_deadlock_detected(const std::pair &mismatch, @@ -108,15 +108,11 @@ } static void push_lock(void *c, const CLockLocation &locklocation) { - if (!lockstack) { - lockstack.reset(new LockStack); - } - std::lock_guard lock(lockdata.dd_mutex); - lockstack->push_back(std::make_pair(c, locklocation)); + g_lockstack.push_back(std::make_pair(c, locklocation)); - for (const std::pair &i : (*lockstack)) { + for (const std::pair &i : g_lockstack) { if (i.first == c) { break; } @@ -125,7 +121,7 @@ if (lockdata.lockorders.count(p1)) { continue; } - lockdata.lockorders[p1] = (*lockstack); + lockdata.lockorders[p1] = g_lockstack; std::pair p2 = std::make_pair(c, i.first); lockdata.invlockorders.insert(p2); @@ -137,7 +133,7 @@ } static void pop_lock() { - (*lockstack).pop_back(); + g_lockstack.pop_back(); } void EnterCritical(const char *pszName, const char *pszFile, int nLine, @@ -151,7 +147,7 @@ std::string LocksHeld() { std::string result; - for (const std::pair &i : *lockstack) { + for (const std::pair &i : g_lockstack) { result += i.second.ToString() + std::string("\n"); } return result; @@ -159,7 +155,7 @@ void AssertLockHeldInternal(const char *pszName, const char *pszFile, int nLine, void *cs) { - for (const std::pair &i : *lockstack) { + for (const std::pair &i : g_lockstack) { if (i.first == cs) { return; } @@ -172,7 +168,7 @@ void AssertLockNotHeldInternal(const char *pszName, const char *pszFile, int nLine, void *cs) { - for (const std::pair &i : *lockstack) { + for (const std::pair &i : g_lockstack) { if (i.first == cs) { fprintf(stderr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s",