diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2020-06-10 10:05:39 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-11 12:04:39 +0000 |
commit | a1c1d823c09afe06ce3418298dd71b5266d6c4f6 (patch) | |
tree | 93203ec7902424e71c068da128dea6e304f02884 /src/mongo/util/tick_source_mock.h | |
parent | e3948d4d8817579b6b03618e64e1b9e8cc2ef086 (diff) | |
download | mongo-a1c1d823c09afe06ce3418298dd71b5266d6c4f6.tar.gz |
SERVER-48668 Make TickSourceMock class thread safe
Diffstat (limited to 'src/mongo/util/tick_source_mock.h')
-rw-r--r-- | src/mongo/util/tick_source_mock.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mongo/util/tick_source_mock.h b/src/mongo/util/tick_source_mock.h index 9010a7edc28..dfbfdd03556 100644 --- a/src/mongo/util/tick_source_mock.h +++ b/src/mongo/util/tick_source_mock.h @@ -29,6 +29,7 @@ #pragma once +#include "mongo/platform/atomic_word.h" #include "mongo/util/tick_source.h" #include "mongo/util/time_support.h" @@ -45,7 +46,7 @@ template <typename D = Milliseconds> class TickSourceMock final : public TickSource { public: TickSource::Tick getTicks() override { - return _currentTicks; + return _currentTicks.load(); }; TickSource::Tick getTicksPerSecond() override { @@ -58,17 +59,17 @@ public: * Advance the ticks by the given amount of milliseconds. */ void advance(const D& duration) { - _currentTicks += duration.count(); + _currentTicks.fetchAndAdd(duration.count()); } /** * Resets the tick count to the given value. */ void reset(TickSource::Tick tick) { - _currentTicks = std::move(tick); + _currentTicks.store(std::move(tick)); } private: - TickSource::Tick _currentTicks = 0; + AtomicWord<TickSource::Tick> _currentTicks{0}; }; } // namespace mongo |