diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-01-04 11:11:05 -0500 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-01-04 11:11:05 -0500 |
commit | b7c7462c564298da54333775f7734e2623dfb08b (patch) | |
tree | 6609a733477cfbefb27f3ea6c71bb7279617f8da /src | |
parent | 775acfcc757aa9beefa8c2f27827ca3edbc5958f (diff) | |
download | mongo-b7c7462c564298da54333775f7734e2623dfb08b.tar.gz |
SERVER-5738 Remove MONGO_ONCE in favor of std::call_once
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/auth/authz_session_external_state_server_common.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/storage/mmap_v1/btree/btree_logic.cpp | 9 | ||||
-rw-r--r-- | src/mongo/dbtests/basictests.cpp | 3 | ||||
-rw-r--r-- | src/mongo/util/debug_util.h | 3 | ||||
-rw-r--r-- | src/mongo/util/debugger.cpp | 11 |
5 files changed, 20 insertions, 13 deletions
diff --git a/src/mongo/db/auth/authz_session_external_state_server_common.cpp b/src/mongo/db/auth/authz_session_external_state_server_common.cpp index e2416596c4b..faf039ba7dc 100644 --- a/src/mongo/db/auth/authz_session_external_state_server_common.cpp +++ b/src/mongo/db/auth/authz_session_external_state_server_common.cpp @@ -32,6 +32,8 @@ #include "mongo/db/auth/authz_session_external_state_server_common.h" +#include <mutex> + #include "mongo/base/status.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/client.h" @@ -43,6 +45,7 @@ namespace mongo { namespace { MONGO_EXPORT_STARTUP_SERVER_PARAMETER(enableLocalhostAuthBypass, bool, true); +std::once_flag checkShouldAllowLocalhostOnceFlag; } // namespace // NOTE: we default _allowLocalhost to true under the assumption that _checkShouldAllowLocalhost @@ -67,11 +70,11 @@ void AuthzSessionExternalStateServerCommon::_checkShouldAllowLocalhost(Operation _allowLocalhost = !_authzManager->hasAnyPrivilegeDocuments(txn); if (_allowLocalhost) { - ONCE { + std::call_once(checkShouldAllowLocalhostOnceFlag, []() { log() << "note: no users configured in admin.system.users, allowing localhost " "access" << std::endl; - } + }); } } diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_logic.cpp b/src/mongo/db/storage/mmap_v1/btree/btree_logic.cpp index b102d6f1b73..f6702fe27aa 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_logic.cpp +++ b/src/mongo/db/storage/mmap_v1/btree/btree_logic.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" +#include <mutex> #include <numeric> #include "mongo/db/client.h" @@ -69,6 +70,10 @@ using std::vector; // creating a new right sibling, it is set as its parent's nextChild as all keys in the right // sibling will be higher than all keys currently in the parent. +namespace { +std::once_flag assertValidFlag; +} // namespace + // // Public Builder logic // @@ -2136,9 +2141,7 @@ void BtreeLogic<BtreeLayout>::assertValid(const std::string& ns, // wassert( z <= 0 ); if (z > 0) { log() << "Btree keys out of order in collection " << ns; - ONCE { - dumpBucket(bucket); - } + std::call_once(assertValidFlag, [&bucket]() { dumpBucket(bucket); }); invariant(false); } } diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp index d9a16934d8e..0dd6f2a28d3 100644 --- a/src/mongo/dbtests/basictests.cpp +++ b/src/mongo/dbtests/basictests.cpp @@ -62,15 +62,12 @@ public: void run() { int first = 0; int second = 0; - int third = 0; for (int i = 0; i < 128; ++i) { incRarely(first); incRarely2(second); - ONCE++ third; } ASSERT_EQUALS(1, first); ASSERT_EQUALS(1, second); - ASSERT_EQUALS(1, third); } private: diff --git a/src/mongo/util/debug_util.h b/src/mongo/util/debug_util.h index 97b3011f1eb..f09072e63e9 100644 --- a/src/mongo/util/debug_util.h +++ b/src/mongo/util/debug_util.h @@ -54,7 +54,4 @@ const bool kDebugBuild = false; #define MONGO_RARELY SOMETIMES(rarely, 128) #define RARELY MONGO_RARELY -#define MONGO_ONCE for (static bool undone = true; undone; undone = false) -#define ONCE MONGO_ONCE - } // namespace mongo diff --git a/src/mongo/util/debugger.cpp b/src/mongo/util/debugger.cpp index 9682c54db14..cb9a8ca3598 100644 --- a/src/mongo/util/debugger.cpp +++ b/src/mongo/util/debugger.cpp @@ -32,6 +32,7 @@ #include "mongo/util/debugger.h" #include <cstdlib> +#include <mutex> #if defined(USE_GDBSERVER) #include <cstdio> @@ -44,6 +45,12 @@ #include "mongo/util/debug_util.h" +#ifndef _WIN32 +namespace { +std::once_flag breakpointOnceFlag; +} // namespace +#endif + namespace mongo { void breakpoint() { #ifdef _WIN32 @@ -53,7 +60,7 @@ void breakpoint() { #endif #ifndef _WIN32 // code to raise a breakpoint in GDB - ONCE { + std::call_once(breakpointOnceFlag, []() { // prevent SIGTRAP from crashing the program if default action is specified and we are not // in gdb struct sigaction current; @@ -63,7 +70,7 @@ void breakpoint() { if (current.sa_handler == SIG_DFL) { signal(SIGTRAP, SIG_IGN); } - } + }); raise(SIGTRAP); #endif |