diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-01-25 18:57:22 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-03-20 18:56:18 -0400 |
commit | b283aecc3a6e65e805c5ffe57b0ad4368faacbfd (patch) | |
tree | 8709b2617b13f102c1fd51b8149d74753beb0648 /src/mongo/util/background_thread_clock_source.h | |
parent | 20e5b17371591f2a72ee9cd3d9b18a3db8d192c8 (diff) | |
download | mongo-b283aecc3a6e65e805c5ffe57b0ad4368faacbfd.tar.gz |
SERVER-21538 Put BGThreadClockSource to sleep when it isn't needed
If it goes through a full granularity of sleeping without being read from, it
will sleep with no timeout until the next attempt to read the clock.
Diffstat (limited to 'src/mongo/util/background_thread_clock_source.h')
-rw-r--r-- | src/mongo/util/background_thread_clock_source.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/mongo/util/background_thread_clock_source.h b/src/mongo/util/background_thread_clock_source.h index 6ea43ed86de..55d0096f58c 100644 --- a/src/mongo/util/background_thread_clock_source.h +++ b/src/mongo/util/background_thread_clock_source.h @@ -45,7 +45,8 @@ namespace mongo { /** * A clock source that uses a periodic timer to build a low-resolution, fast-to-read clock. * Essentially uses a background thread that repeatedly sleeps for X amount of milliseconds - * and wakes up to store the current time. + * and wakes up to store the current time. If nothing reads the time for a whole granularity, the + * thread will sleep until it is needed again. */ class BackgroundThreadClockSource final : public ClockSource { MONGO_DISALLOW_COPYING(BackgroundThreadClockSource); @@ -56,18 +57,28 @@ public: Milliseconds getPrecision() override; Date_t now() override; + /** + * Doesn't count as a call to now() for determining whether this ClockSource is idle. + */ + int64_t peekNowForTest() const { + return _current.load(); + } + private: + Date_t _slowNow(); void _startTimerThread(); - void _updateCurrent(); + int64_t _updateCurrent_inlock(); const std::unique_ptr<ClockSource> _clockSource; - AtomicInt64 _current; + AtomicInt64 _current{0}; // 0 if _timer is paused due to idleness. + AtomicBool _timerWillPause{true}; // If true when _timer wakes up, it will pause. const Milliseconds _granularity; stdx::mutex _mutex; stdx::condition_variable _condition; - bool _shutdownTimer; + bool _inShutdown = false; + bool _started = false; stdx::thread _timer; }; |