refactor: Replace RecursiveMutex with Mutex in rpc/server.cpp

This commit is contained in:
Hennadii Stepanov 2020-06-28 09:54:17 +03:00
parent d06cf34656
commit 6fdfeebcc7
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

View File

@ -20,10 +20,10 @@
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
static RecursiveMutex cs_rpcWarmup; static Mutex g_rpc_warmup_mutex;
static std::atomic<bool> g_rpc_running{false}; static std::atomic<bool> g_rpc_running{false};
static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true; static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started"; static std::string rpcWarmupStatus GUARDED_BY(g_rpc_warmup_mutex) = "RPC server started";
/* Timer-creating functions */ /* Timer-creating functions */
static RPCTimerInterface* timerInterface = nullptr; static RPCTimerInterface* timerInterface = nullptr;
/* Map of name to timer. */ /* Map of name to timer. */
@ -327,20 +327,20 @@ void RpcInterruptionPoint()
void SetRPCWarmupStatus(const std::string& newStatus) void SetRPCWarmupStatus(const std::string& newStatus)
{ {
LOCK(cs_rpcWarmup); LOCK(g_rpc_warmup_mutex);
rpcWarmupStatus = newStatus; rpcWarmupStatus = newStatus;
} }
void SetRPCWarmupFinished() void SetRPCWarmupFinished()
{ {
LOCK(cs_rpcWarmup); LOCK(g_rpc_warmup_mutex);
assert(fRPCInWarmup); assert(fRPCInWarmup);
fRPCInWarmup = false; fRPCInWarmup = false;
} }
bool RPCIsInWarmup(std::string *outStatus) bool RPCIsInWarmup(std::string *outStatus)
{ {
LOCK(cs_rpcWarmup); LOCK(g_rpc_warmup_mutex);
if (outStatus) if (outStatus)
*outStatus = rpcWarmupStatus; *outStatus = rpcWarmupStatus;
return fRPCInWarmup; return fRPCInWarmup;
@ -439,7 +439,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
{ {
// Return immediately if in warmup // Return immediately if in warmup
{ {
LOCK(cs_rpcWarmup); LOCK(g_rpc_warmup_mutex);
if (fRPCInWarmup) if (fRPCInWarmup)
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus); throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
} }