Merge #19220: refactor: Replace RecursiveMutex with Mutex in warnings.cpp

bacbfb61eee6d3c32de3db4dea3f585c7159b643 refactor: Replace RecursiveMutex with Mutex in warnings.cpp (Hennadii Stepanov)

Pull request description:

  The functions that could lock this mutex, i.e., `SetMiscWarning()`, `{S,G}etfLargeWorkForkFound()`, `SetfLargeWorkInvalidChainFound()`, `GetWarnings()`, do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the `g_warnings_mutex` could be a non-recursive mutex.

  Related to #19180.

ACKs for top commit:
  laanwj:
    Code review ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643
  MarcoFalke:
    ACK bacbfb61eee6d3c32de3db4dea3f585c7159b643 , reviewed with -W  --word-diff-regex=. 🎿

Tree-SHA512: cc06d3d30e4051115d176dcfbd496c8562a70087369bccde756c1de42d7dc3f415ef20d3d69ad2599c1d0cd4228d604d7564adc17beac7b6ff92b924b8c20d54
This commit is contained in:
MarcoFalke 2020-06-09 08:54:52 -04:00 committed by Pasta
parent 480fc90ef7
commit 12b5cfcff0
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -9,32 +9,32 @@
#include <warnings.h> #include <warnings.h>
#include <hash.h> #include <hash.h>
static RecursiveMutex cs_warnings; static Mutex g_warnings_mutex;
static std::string strMiscWarning GUARDED_BY(cs_warnings); static std::string strMiscWarning GUARDED_BY(g_warnings_mutex);
static bool fLargeWorkForkFound GUARDED_BY(cs_warnings) = false; static bool fLargeWorkForkFound GUARDED_BY(g_warnings_mutex) = false;
static bool fLargeWorkInvalidChainFound GUARDED_BY(cs_warnings) = false; static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
void SetMiscWarning(const std::string& strWarning) void SetMiscWarning(const std::string& strWarning)
{ {
LOCK(cs_warnings); LOCK(g_warnings_mutex);
strMiscWarning = strWarning; strMiscWarning = strWarning;
} }
void SetfLargeWorkForkFound(bool flag) void SetfLargeWorkForkFound(bool flag)
{ {
LOCK(cs_warnings); LOCK(g_warnings_mutex);
fLargeWorkForkFound = flag; fLargeWorkForkFound = flag;
} }
bool GetfLargeWorkForkFound() bool GetfLargeWorkForkFound()
{ {
LOCK(cs_warnings); LOCK(g_warnings_mutex);
return fLargeWorkForkFound; return fLargeWorkForkFound;
} }
void SetfLargeWorkInvalidChainFound(bool flag) void SetfLargeWorkInvalidChainFound(bool flag)
{ {
LOCK(cs_warnings); LOCK(g_warnings_mutex);
fLargeWorkInvalidChainFound = flag; fLargeWorkInvalidChainFound = flag;
} }
@ -44,7 +44,7 @@ std::string GetWarnings(const std::string& strFor)
std::string strGUI; std::string strGUI;
const std::string uiAlertSeparator = "<hr />"; const std::string uiAlertSeparator = "<hr />";
LOCK(cs_warnings); LOCK(g_warnings_mutex);
if (!CLIENT_VERSION_IS_RELEASE) { if (!CLIENT_VERSION_IS_RELEASE) {
strStatusBar = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"; strStatusBar = "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications";