Skip to content

Commit 1f7fe59

Browse files
author
MarcoFalke
committed
Merge #19111: Limit scope of all global std::once_flag
fa9c675 Limit scope of all global std::once_flag (MarcoFalke) Pull request description: `once_flag` is a helper (as the name might suggest) to execute a callable only once. Thus, the scope of the flag does never need to extend beyond where the callable is called. Typically this is function scope. Move all the flags to function scope to * simplify code review * avoid mistakes where similarly named flags are accidentally exchanged * avoid polluting the global scope ACKs for top commit: hebasto: ACK fa9c675, tested on Linux Mint 19.3 (x86_64). promag: Code review ACK fa9c675. Tree-SHA512: 095a0c11d93d0ddcb82b3c71676090ecc7e3de3d5e7a2a63ab2583093be279242acac43523bbae2060b4dcfa8f92b54256a0e91fbbae78fa92d2d49e9db62e57
2 parents 4430744 + fa9c675 commit 1f7fe59

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

src/rpc/server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
static RecursiveMutex cs_rpcWarmup;
2424
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;
2725
static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true;
2826
static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started";
2927
/* Timer-creating functions */
@@ -295,6 +293,7 @@ void StartRPC()
295293

296294
void InterruptRPC()
297295
{
296+
static std::once_flag g_rpc_interrupt_flag;
298297
// This function could be called twice if the GUI has been started with -server=1.
299298
std::call_once(g_rpc_interrupt_flag, []() {
300299
LogPrint(BCLog::RPC, "Interrupting RPC\n");
@@ -305,6 +304,7 @@ void InterruptRPC()
305304

306305
void StopRPC()
307306
{
307+
static std::once_flag g_rpc_stop_flag;
308308
// This function could be called twice if the GUI has been started with -server=1.
309309
assert(!g_rpc_running);
310310
std::call_once(g_rpc_stop_flag, []() {

src/support/lockedpool.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#endif
3030

3131
LockedPoolManager* LockedPoolManager::_instance = nullptr;
32-
std::once_flag LockedPoolManager::init_flag;
3332

3433
/*******************************************************************************/
3534
// Utilities

src/support/lockedpool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ class LockedPoolManager : public LockedPool
221221
/** Return the current instance, or create it once */
222222
static LockedPoolManager& Instance()
223223
{
224-
std::call_once(LockedPoolManager::init_flag, LockedPoolManager::CreateInstance);
224+
static std::once_flag init_flag;
225+
std::call_once(init_flag, LockedPoolManager::CreateInstance);
225226
return *LockedPoolManager::_instance;
226227
}
227228

@@ -234,7 +235,6 @@ class LockedPoolManager : public LockedPool
234235
static bool LockingFailed();
235236

236237
static LockedPoolManager* _instance;
237-
static std::once_flag init_flag;
238238
};
239239

240240
#endif // BITCOIN_SUPPORT_LOCKEDPOOL_H

0 commit comments

Comments
 (0)