diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-14 20:24:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-14 20:24:25 +0200 |
commit | a9b2923859dff064aa5a976cf3cbf61674f806bd (patch) | |
tree | e8a2aa67bb6e4041cecf3ae77bda8c8dabfe5a2f /vespalib | |
parent | bf738b79b217814f11bc3dc57b5d0e6bad8cd1a2 (diff) | |
parent | 433d1fccf19f4fd390b54ac7c149c17529a37e6a (diff) |
Merge pull request #14877 from vespa-engine/balder/gc-unused-code-and-use-condition_variable
GC unuse code and use std::mutex/std:condition_variable over vespalib…
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; |