diff options
Diffstat (limited to 'src/mongo/db/global_timestamp.cpp')
-rw-r--r-- | src/mongo/db/global_timestamp.cpp | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/src/mongo/db/global_timestamp.cpp b/src/mongo/db/global_timestamp.cpp index 536d9d17b98..36ac4f539f8 100644 --- a/src/mongo/db/global_timestamp.cpp +++ b/src/mongo/db/global_timestamp.cpp @@ -34,48 +34,46 @@ #include "mongo/util/log.h" namespace { - mongo::stdx::mutex globalTimestampMutex; - mongo::Timestamp globalTimestamp(0, 0); +mongo::stdx::mutex globalTimestampMutex; +mongo::Timestamp globalTimestamp(0, 0); - bool skewed(const mongo::Timestamp& val) { - if (val.getInc() & 0x80000000) { - mongo::warning() << "clock skew detected prev: " << val.getSecs() - << " now: " << (unsigned) time(0) << std::endl; - return true; - } - - return false; +bool skewed(const mongo::Timestamp& val) { + if (val.getInc() & 0x80000000) { + mongo::warning() << "clock skew detected prev: " << val.getSecs() + << " now: " << (unsigned)time(0) << std::endl; + return true; } + + return false; +} } namespace mongo { - void setGlobalTimestamp(const Timestamp& newTime) { - stdx::lock_guard<stdx::mutex> lk(globalTimestampMutex); - globalTimestamp = newTime; - } - - Timestamp getLastSetTimestamp() { - stdx::lock_guard<stdx::mutex> lk(globalTimestampMutex); - return globalTimestamp; - } +void setGlobalTimestamp(const Timestamp& newTime) { + stdx::lock_guard<stdx::mutex> lk(globalTimestampMutex); + globalTimestamp = newTime; +} - Timestamp getNextGlobalTimestamp() { - stdx::lock_guard<stdx::mutex> lk(globalTimestampMutex); +Timestamp getLastSetTimestamp() { + stdx::lock_guard<stdx::mutex> lk(globalTimestampMutex); + return globalTimestamp; +} - const unsigned now = (unsigned) time(0); - const unsigned globalSecs = globalTimestamp.getSecs(); - if ( globalSecs == now ) { - globalTimestamp = Timestamp(globalSecs, globalTimestamp.getInc() + 1); - } - else if ( now < globalSecs ) { - globalTimestamp = Timestamp(globalSecs, globalTimestamp.getInc() + 1); - // separate function to keep out of the hot code path - fassert(17449, !skewed(globalTimestamp)); - } - else { - globalTimestamp = Timestamp(now, 1); - } +Timestamp getNextGlobalTimestamp() { + stdx::lock_guard<stdx::mutex> lk(globalTimestampMutex); - return globalTimestamp; + const unsigned now = (unsigned)time(0); + const unsigned globalSecs = globalTimestamp.getSecs(); + if (globalSecs == now) { + globalTimestamp = Timestamp(globalSecs, globalTimestamp.getInc() + 1); + } else if (now < globalSecs) { + globalTimestamp = Timestamp(globalSecs, globalTimestamp.getInc() + 1); + // separate function to keep out of the hot code path + fassert(17449, !skewed(globalTimestamp)); + } else { + globalTimestamp = Timestamp(now, 1); } + + return globalTimestamp; +} } |