diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-14 17:53:06 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-14 17:57:29 +0000 |
commit | 433d1fccf19f4fd390b54ac7c149c17529a37e6a (patch) | |
tree | e31c4021dfc3571ed21849af02e703d00b564a21 /vespalib | |
parent | 1ad0641192b439447750c49fee0ca6255d4601fd (diff) |
GC unuse code and use std::mutex/std:condition_variable over vespalib::Monitor
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/simple_thread_bundle.cpp | 8 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/simple_thread_bundle.h | 26 |
2 files changed, 22 insertions, 12 deletions
diff --git a/vespalib/src/vespa/vespalib/util/simple_thread_bundle.cpp b/vespalib/src/vespa/vespalib/util/simple_thread_bundle.cpp index e0d78c5d1b7..4f93f891cf8 100644 --- a/vespalib/src/vespa/vespalib/util/simple_thread_bundle.cpp +++ b/vespalib/src/vespa/vespalib/util/simple_thread_bundle.cpp @@ -50,6 +50,14 @@ Runnable::UP chain(Runnable::UP first, Runnable::UP second) { //----------------------------------------------------------------------------- +Signal::Signal() noexcept + : valid(true), + generation(0), + monitor(std::make_unique<std::mutex>()), + cond(std::make_unique<std::condition_variable>()) +{} +Signal::~Signal() = default; + SimpleThreadBundle::Pool::Pool(size_t bundleSize) : _lock(), _bundleSize(bundleSize), diff --git a/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h b/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h index 135fc2d7562..40844b277f1 100644 --- a/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h +++ b/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h @@ -6,7 +6,6 @@ #include "thread.h" #include "runnable.h" #include "thread_bundle.h" -#include "noncopyable.hpp" namespace vespalib { @@ -46,32 +45,35 @@ struct Part { struct Signal { bool valid; size_t generation; - Monitor monitor; - Signal() noexcept : valid(true), generation(0), monitor() {} + std::unique_ptr<std::mutex> monitor; + std::unique_ptr<std::condition_variable> cond; + Signal() noexcept; + Signal(Signal &&) noexcept = default; + ~Signal(); size_t wait(size_t &localGen) { - MonitorGuard guard(monitor); + std::unique_lock guard(*monitor); while (localGen == generation) { - guard.wait(); + cond->wait(guard); } size_t diff = (generation - localGen); localGen = generation; return (valid ? diff : 0); } void send() { - MonitorGuard guard(monitor); + std::lock_guard guard(*monitor); ++generation; - guard.signal(); + cond->notify_one(); } void broadcast() { - MonitorGuard guard(monitor); + std::lock_guard guard(*monitor); ++generation; - guard.broadcast(); + cond->notify_all(); } void cancel() { - MonitorGuard guard(monitor); + std::lock_guard guard(*monitor); ++generation; valid = false; - guard.broadcast(); + cond->notify_all(); } }; @@ -105,7 +107,7 @@ public: }; private: - struct Worker : Runnable, noncopyable { + struct Worker : Runnable { using UP = std::unique_ptr<Worker>; Thread thread; Signal &signal; |