diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-08 21:57:35 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-10-08 21:57:35 +0000 |
commit | a51725cfc47c215785ac4b24c6e18bf3d5ea475b (patch) | |
tree | 42abc8a4ac1783f0816ffcdd7b85c30e07e7e3d3 /vespalib | |
parent | a4d0cd759eed68318afebbaddbc4baddc70416e2 (diff) |
- GC the last usages of vespalib::Lock.
- Now it is only vespalib::Monitor left
Diffstat (limited to 'vespalib')
9 files changed, 14 insertions, 86 deletions
diff --git a/vespalib/src/tests/executor/blocking_executor_stress.cpp b/vespalib/src/tests/executor/blocking_executor_stress.cpp index b753dc69373..27367f6677c 100644 --- a/vespalib/src/tests/executor/blocking_executor_stress.cpp +++ b/vespalib/src/tests/executor/blocking_executor_stress.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/blockingthreadstackexecutor.h> #include <vespa/vespalib/util/executor.h> -#include <vespa/vespalib/util/sync.h> #include <atomic> using namespace vespalib; @@ -26,7 +25,7 @@ struct MyTask : Executor::Task { size_t size; size_t data; MyTask(size_t size_in) : size(size_in), data(0) {} - virtual void run() override { + void run() override { data += do_stuff(size); ++tasks_run; data += do_stuff(size); diff --git a/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp b/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp index c2a3e66c671..46db619516a 100644 --- a/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp +++ b/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp @@ -3,7 +3,6 @@ #include <vespa/vespalib/util/blockingthreadstackexecutor.h> #include <vespa/vespalib/util/executor.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/backtrace.h> #include <thread> diff --git a/vespalib/src/tests/executor/threadstackexecutor_test.cpp b/vespalib/src/tests/executor/threadstackexecutor_test.cpp index 9d69adcd96a..b43a75f8244 100644 --- a/vespalib/src/tests/executor/threadstackexecutor_test.cpp +++ b/vespalib/src/tests/executor/threadstackexecutor_test.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/threadstackexecutor.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/backtrace.h> #include <atomic> diff --git a/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp b/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp index eca43ea5cec..f04fe549c09 100644 --- a/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp +++ b/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp @@ -3,7 +3,6 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/net/async_resolver.h> #include <vespa/vespalib/net/socket_spec.h> -#include <vespa/vespalib/util/sync.h> #include <atomic> using namespace vespalib; diff --git a/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp b/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp index 5641d751f34..d3c562c583c 100644 --- a/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp @@ -3,7 +3,6 @@ #include <vespa/vespalib/util/simple_thread_bundle.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/box.h> -#include <vespa/vespalib/util/sync.h> using namespace vespalib; using namespace vespalib::fixed_thread_bundle; diff --git a/vespalib/src/tests/sync/sync_test.cpp b/vespalib/src/tests/sync/sync_test.cpp index 0925ce060a0..3a2cf0ea7a0 100644 --- a/vespalib/src/tests/sync/sync_test.cpp +++ b/vespalib/src/tests/sync/sync_test.cpp @@ -14,9 +14,6 @@ private: std::condition_variable *_cond; public: - TryLock(const Lock &lock) - : _guard(*lock._mutex, std::try_to_lock), _cond(nullptr) - {} TryLock(const Monitor &mon) : _guard(*mon._mutex, std::try_to_lock), _cond(_guard ? mon._cond.get() : nullptr) @@ -49,10 +46,8 @@ using namespace vespalib; class Test : public TestApp { private: - Lock _lock; Monitor _monitor; - LockGuard lockLock() { return LockGuard(_lock); } LockGuard lockMonitor() { return LockGuard(_monitor); } MonitorGuard obtainMonitor() { return MonitorGuard(_monitor); } public: @@ -61,7 +56,8 @@ public: int Main() override; }; -Test::~Test() {} +Test::~Test() = default; + void Test::testCountDownLatch() { { @@ -108,21 +104,6 @@ int Test::Main() { TEST_INIT("sync_test"); - { - Lock lock; - { - CHECK_UNLOCKED(lock); - LockGuard guard(lock); - CHECK_LOCKED(lock); - } - CHECK_UNLOCKED(lock); - { - LockGuard guard(lock); - CHECK_LOCKED(lock); - guard.unlock(); - CHECK_UNLOCKED(lock); - } - } // you can use a LockGuard to lock a Monitor { Monitor monitor; @@ -159,12 +140,7 @@ Test::Main() } // you can lock const objects - { - const Lock lock; - CHECK_UNLOCKED(lock); - LockGuard guard(lock); - CHECK_LOCKED(lock); - } + { const Monitor lock; CHECK_UNLOCKED(lock); @@ -179,7 +155,7 @@ Test::Main() } // LockGuard/MonitorGuard have destructive move { - Lock lock; + Monitor lock; CHECK_UNLOCKED(lock); LockGuard a(lock); CHECK_LOCKED(lock); @@ -204,19 +180,13 @@ Test::Main() } // Destructive copy also works for return value handover { - CHECK_UNLOCKED(_lock); CHECK_UNLOCKED(_monitor); { - CHECK_UNLOCKED(_lock); CHECK_UNLOCKED(_monitor); - LockGuard a(lockLock()); - CHECK_LOCKED(_lock); CHECK_UNLOCKED(_monitor); LockGuard b = lockMonitor(); // copy, not assign - CHECK_LOCKED(_lock); CHECK_LOCKED(_monitor); } - CHECK_UNLOCKED(_lock); CHECK_UNLOCKED(_monitor); } { @@ -230,8 +200,8 @@ Test::Main() } // Test that guards can be matched to locks/monitors { - Lock lock1; - Lock lock2; + Monitor lock1; + Monitor lock2; LockGuard lockGuard1(lock1); LockGuard lockGuard2(lock2); EXPECT_TRUE(lockGuard1.locks(lock1)); diff --git a/vespalib/src/vespa/vespalib/util/sync.cpp b/vespalib/src/vespa/vespalib/util/sync.cpp index ac55f12c341..1f7a5215c46 100644 --- a/vespalib/src/vespa/vespalib/util/sync.cpp +++ b/vespalib/src/vespa/vespalib/util/sync.cpp @@ -5,15 +5,8 @@ namespace vespalib { -Lock::Lock() noexcept - : _mutex(std::make_unique<std::mutex>()) -{} -Lock::Lock(Lock &&rhs) noexcept = default; -Lock::~Lock() = default; - - Monitor::Monitor() noexcept - : Lock(), + : _mutex(std::make_unique<std::mutex>()), _cond(std::make_unique<std::condition_variable>()) {} Monitor::Monitor(Monitor &&rhs) noexcept = default; @@ -22,7 +15,7 @@ Monitor::~Monitor() = default; LockGuard::LockGuard() : _guard() {} LockGuard::LockGuard(LockGuard &&rhs) noexcept : _guard(std::move(rhs._guard)) { } -LockGuard::LockGuard(const Lock &lock) : _guard(*lock._mutex) { } +LockGuard::LockGuard(const Monitor &lock) : _guard(*lock._mutex) { } LockGuard & LockGuard::operator=(LockGuard &&rhs) noexcept{ @@ -41,7 +34,7 @@ LockGuard::unlock() { LockGuard::~LockGuard() = default; bool -LockGuard::locks(const Lock& lock) const { +LockGuard::locks(const Monitor & lock) const { return (_guard && _guard.mutex() == lock._mutex.get()); } diff --git a/vespalib/src/vespa/vespalib/util/sync.h b/vespalib/src/vespa/vespalib/util/sync.h index 3207206a753..d66a53cf539 100644 --- a/vespalib/src/vespa/vespalib/util/sync.h +++ b/vespalib/src/vespa/vespalib/util/sync.h @@ -9,35 +9,6 @@ namespace vespalib { /** - * @brief A Lock is a synchronization primitive used to ensure mutual - * exclusion. - * - * Use a LockGuard to hold a lock inside a scope. - * - * It is possible to obtain a lock on a const Lock object. - * - * @see TryLock - **/ -class Lock -{ -protected: - friend class LockGuard; - friend class TryLock; - - std::unique_ptr<std::mutex> _mutex; -public: - /** - * @brief Create a new Lock. - * - * Creates a Lock that has mutex instrumentation disabled. - **/ - Lock() noexcept; - Lock(Lock && rhs) noexcept; - ~Lock(); -}; - - -/** * @brief A Monitor is a synchronization primitive used to protect * data access and also facilitate signaling and waiting between * threads. @@ -49,13 +20,14 @@ public: * * @see TryLock **/ -class Monitor : public Lock +class Monitor { private: friend class LockGuard; friend class MonitorGuard; friend class TryLock; + std::unique_ptr<std::mutex> _mutex; std::unique_ptr<std::condition_variable> _cond; public: /** @@ -106,7 +78,7 @@ public: * * @param lock take it **/ - LockGuard(const Lock &lock); + LockGuard(const Monitor &lock); LockGuard &operator=(LockGuard &&rhs) noexcept; @@ -129,7 +101,7 @@ public: * Allow code to match guard with lock. This allows functions to take a * guard ref as input, ensuring that the caller have grabbed a lock. */ - bool locks(const Lock& lock) const; + bool locks(const Monitor& lock) const; }; diff --git a/vespalib/src/vespa/vespalib/util/zstdcompressor.cpp b/vespalib/src/vespa/vespalib/util/zstdcompressor.cpp index 2f09abf4846..931f727ad6c 100644 --- a/vespalib/src/vespa/vespalib/util/zstdcompressor.cpp +++ b/vespalib/src/vespa/vespalib/util/zstdcompressor.cpp @@ -2,9 +2,7 @@ #include "zstdcompressor.h" #include <vespa/vespalib/util/alloc.h> -#include <vespa/vespalib/util/sync.h> #include <zstd.h> -#include <vector> #include <cassert> using vespalib::alloc::Alloc; |