Skip to content

Commit 2af56d6

Browse files
committed
Merge #19399: refactor: Replace RecursiveMutex with Mutex in rpc/server.cpp
6fdfeeb 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 6fdfeeb MarcoFalke: ACK 6fdfeeb Tree-SHA512: 05a8ac58c0cd6a3c9afad9e06ad78059642e3e97715e129f379c0bf6dccdb58e70d05d965f23e7432fd3f02d7f97967a778ffb8e424837891d9d785a9e98964c
2 parents 8d3187f + 6fdfeeb commit 2af56d6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/rpc/server.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include <mutex>
2121
#include <unordered_map>
2222

23-
static RecursiveMutex cs_rpcWarmup;
23+
static Mutex g_rpc_warmup_mutex;
2424
static std::atomic<bool> g_rpc_running{false};
25-
static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true;
26-
static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started";
25+
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
26+
static std::string rpcWarmupStatus GUARDED_BY(g_rpc_warmup_mutex) = "RPC server started";
2727
/* Timer-creating functions */
2828
static RPCTimerInterface* timerInterface = nullptr;
2929
/* Map of name to timer. */
@@ -327,20 +327,20 @@ void RpcInterruptionPoint()
327327

328328
void SetRPCWarmupStatus(const std::string& newStatus)
329329
{
330-
LOCK(cs_rpcWarmup);
330+
LOCK(g_rpc_warmup_mutex);
331331
rpcWarmupStatus = newStatus;
332332
}
333333

334334
void SetRPCWarmupFinished()
335335
{
336-
LOCK(cs_rpcWarmup);
336+
LOCK(g_rpc_warmup_mutex);
337337
assert(fRPCInWarmup);
338338
fRPCInWarmup = false;
339339
}
340340

341341
bool RPCIsInWarmup(std::string *outStatus)
342342
{
343-
LOCK(cs_rpcWarmup);
343+
LOCK(g_rpc_warmup_mutex);
344344
if (outStatus)
345345
*outStatus = rpcWarmupStatus;
346346
return fRPCInWarmup;
@@ -439,7 +439,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
439439
{
440440
// Return immediately if in warmup
441441
{
442-
LOCK(cs_rpcWarmup);
442+
LOCK(g_rpc_warmup_mutex);
443443
if (fRPCInWarmup)
444444
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
445445
}

0 commit comments

Comments
 (0)