aboutsummaryrefslogtreecommitdiff
path: root/src/sync.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2020-03-01 14:22:37 +1000
committerAnthony Towns <aj@erisian.com.au>2020-03-06 23:13:31 +1000
commitb9c426012770d166e6ebfab27689be44e6e89aa5 (patch)
treeb3a975c6133c21bdce11ff66ac8fc915c7bc6f81 /src/sync.cpp
parent306f71b4eb4a0fd8e64f47dc008bc235b80b13d9 (diff)
sync.h: add REVERSE_LOCK
Diffstat (limited to 'src/sync.cpp')
-rw-r--r--src/sync.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/sync.cpp b/src/sync.cpp
index 924e7b5bb0..71657a7439 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -13,7 +13,7 @@
#include <util/strencodings.h>
#include <util/threadnames.h>
-
+#include <system_error>
#include <map>
#include <set>
@@ -60,6 +60,11 @@ struct CLockLocation {
mutexName, sourceFile, itostr(sourceLine), (fTry ? " (TRY)" : ""), m_thread_name);
}
+ std::string Name() const
+ {
+ return mutexName;
+ }
+
private:
bool fTry;
std::string mutexName;
@@ -155,6 +160,18 @@ void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs
push_lock(cs, CLockLocation(pszName, pszFile, nLine, fTry, util::ThreadGetInternalName()));
}
+void CheckLastCritical(void* cs, std::string& lockname, const char* guardname, const char* file, int line)
+{
+ if (!g_lockstack.empty()) {
+ const auto& lastlock = g_lockstack.back();
+ if (lastlock.first == cs) {
+ lockname = lastlock.second.Name();
+ return;
+ }
+ }
+ throw std::system_error(EPERM, std::generic_category(), strprintf("%s:%s %s was not most recent critical section locked", file, line, guardname));
+}
+
void LeaveCritical()
{
pop_lock();