mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Merge #19399: refactor: Replace RecursiveMutex with Mutex in rpc/server.cpp
6fdfeebcc79df62c8bf1cf4b6e9e97d6aefb3eb3 refactor: Replace RecursiveMutex with Mutex in rpc/server.cpp (Hennadii Stepanov) Pull request description: The functions that could lock this mutex, i.e., `SetRPCWarmupStatus()`, `SetRPCWarmupFinished()`, `RPCIsInWarmup()`, `CRPCTable::execute()`, do not call itself recursively, and do not call each other either directly or indirectly. Therefore, the `g_rpc_warmup_mutex` could be a non-recursive mutex. Related to #19303. ACKs for top commit: laanwj: ACK 6fdfeebcc79df62c8bf1cf4b6e9e97d6aefb3eb3 MarcoFalke: ACK 6fdfeebcc79df62c8bf1cf4b6e9e97d6aefb3eb3 Tree-SHA512: 05a8ac58c0cd6a3c9afad9e06ad78059642e3e97715e129f379c0bf6dccdb58e70d05d965f23e7432fd3f02d7f97967a778ffb8e424837891d9d785a9e98964c
This commit is contained in:
parent
dd2558b74a
commit
9feb82056c
@ -20,10 +20,10 @@
|
|||||||
#include <memory> // for unique_ptr
|
#include <memory> // for unique_ptr
|
||||||
#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. */
|
||||||
@ -346,20 +346,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;
|
||||||
@ -457,7 +457,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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user