|
15 | 15 | #include <boost/algorithm/string/classification.hpp> |
16 | 16 | #include <boost/algorithm/string/split.hpp> |
17 | 17 |
|
| 18 | +#include <cassert> |
18 | 19 | #include <memory> // for unique_ptr |
| 20 | +#include <mutex> |
19 | 21 | #include <unordered_map> |
20 | 22 |
|
21 | 23 | static RecursiveMutex cs_rpcWarmup; |
22 | 24 | static std::atomic<bool> g_rpc_running{false}; |
| 25 | +static std::once_flag g_rpc_interrupt_flag; |
| 26 | +static std::once_flag g_rpc_stop_flag; |
23 | 27 | static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true; |
24 | 28 | static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started"; |
25 | 29 | /* Timer-creating functions */ |
@@ -290,17 +294,24 @@ void StartRPC() |
290 | 294 |
|
291 | 295 | void InterruptRPC() |
292 | 296 | { |
293 | | - LogPrint(BCLog::RPC, "Interrupting RPC\n"); |
294 | | - // Interrupt e.g. running longpolls |
295 | | - g_rpc_running = false; |
| 297 | + // This function could be called twice if the GUI has been started with -server=1. |
| 298 | + std::call_once(g_rpc_interrupt_flag, []() { |
| 299 | + LogPrint(BCLog::RPC, "Interrupting RPC\n"); |
| 300 | + // Interrupt e.g. running longpolls |
| 301 | + g_rpc_running = false; |
| 302 | + }); |
296 | 303 | } |
297 | 304 |
|
298 | 305 | void StopRPC() |
299 | 306 | { |
300 | | - LogPrint(BCLog::RPC, "Stopping RPC\n"); |
301 | | - deadlineTimers.clear(); |
302 | | - DeleteAuthCookie(); |
303 | | - g_rpcSignals.Stopped(); |
| 307 | + // This function could be called twice if the GUI has been started with -server=1. |
| 308 | + assert(!g_rpc_running); |
| 309 | + std::call_once(g_rpc_stop_flag, []() { |
| 310 | + LogPrint(BCLog::RPC, "Stopping RPC\n"); |
| 311 | + deadlineTimers.clear(); |
| 312 | + DeleteAuthCookie(); |
| 313 | + g_rpcSignals.Stopped(); |
| 314 | + }); |
304 | 315 | } |
305 | 316 |
|
306 | 317 | bool IsRPCRunning() |
|
0 commit comments