sync.h: add REVERSE_LOCK
This commit is contained in:
1 parent
306f71b4eb
commit
b9c4260127
3 files changed
+94
-9
No files matched your search
+18
-1
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user