mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
sync.h: add REVERSE_LOCK
This commit is contained in:
19
src/sync.cpp
19
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();
|
||||
|
||||
Reference in New Issue
Block a user