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 | |
parent | a4d0cd759eed68318afebbaddbc4baddc70416e2 (diff) |
- GC the last usages of vespalib::Lock.
- Now it is only vespalib::Monitor left
36 files changed, 33 insertions, 202 deletions
diff --git a/config/src/tests/file_subscription/file_subscription.cpp b/config/src/tests/file_subscription/file_subscription.cpp index 836ca6593f8..468180cd78f 100644 --- a/config/src/tests/file_subscription/file_subscription.cpp +++ b/config/src/tests/file_subscription/file_subscription.cpp @@ -6,7 +6,6 @@ #include <vespa/config/common/exceptions.h> #include <vespa/config/common/sourcefactory.h> #include <vespa/config/common/configcontext.h> -#include <vespa/vespalib/util/sync.h> #include <fstream> #include <config-my.h> #include <config-foo.h> diff --git a/config/src/vespa/config/frt/frtconnection.h b/config/src/vespa/config/frt/frtconnection.h index bde3e79b83c..9e6ef688607 100644 --- a/config/src/vespa/config/frt/frtconnection.h +++ b/config/src/vespa/config/frt/frtconnection.h @@ -2,7 +2,6 @@ #pragma once #include "connection.h" -#include <vespa/vespalib/util/sync.h> #include <vespa/config/common/timingvalues.h> #include <atomic> diff --git a/document/src/vespa/document/util/queue.h b/document/src/vespa/document/util/queue.h index af0ce85fad1..7e3c98333c8 100644 --- a/document/src/vespa/document/util/queue.h +++ b/document/src/vespa/document/util/queue.h @@ -5,8 +5,7 @@ #include <vespa/vespalib/util/sync.h> #define UNUSED_PARAM(p) -namespace document -{ +namespace document { // XXX move to vespalib (or remove) /** @@ -202,79 +201,7 @@ public: } return retval; } -#if 0 -// XXX unused? - size_t max() const { return _max; } - size_t lowWaterMark() const { return _lowWaterMark; } - void max(size_t v) - { - vespalib::MonitorGuard guard(this->_cond); - _max = v; _lowWaterMark = _max/2; - } - void lowWaterMark(size_t v) - { - vespalib::MonitorGuard guard(this->_cond); - _lowWaterMark = v; - } -#endif -}; - -template <typename T, typename Q=std::queue<T> > -class QueueWithMaxSerialized : public QueueWithMax<T, Q> -{ -public: - QueueWithMaxSerialized(size_t max_=1000000, size_t lowWaterMark_=500000) : QueueWithMax<T, Q>(max_, lowWaterMark_) { } - virtual void add(const T& msg) - { - if (msg != NULL) { - this->_size += msg->getSerializedSize(); - } - } - virtual void sub(const T& msg) - { - if (msg != NULL) { - this->_size -= msg->getSerializedSize(); - } - } -}; - -#if 0 - -/** - This is an fast Q that reduces lock/unlock to a minimum and ditto with - context swithes on notify/wait. enque/deque have no atomic operations - unless it is empty/full. This limits the use to situations where there are - both single consumers and single producers. -*/ -template <typename T> -class QueueSingleProducerConsumer { -private: - typedef std::vector<T> Q; -public: - typedef typename Q::iterator iterator; - enum { end=-1 }; - QueueSingleProducerConsumer(size_t max=1000, - size_t highWaterMark=999, - size_t lowWaterMark=1); - T * wait(int timeOut=-1) - { - T * retval(NULL); - if (empty()) { - _cond.Wait(timeOut); - } - return retval; - } - const T & head() const { return _q[_readPos]; } - void removeHead() { ~_q[_readPos](); _readPos++; } - bool deque(); -private: - std::vector<T> _q; - size_t _readPos; - size_t _writePos; - FastOS_Condition _cond; }; -#endif - } // namespace document diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.cpp index 8b303d10e0a..82cda6c773f 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.cpp @@ -41,9 +41,7 @@ AsyncInitializationPolicy::AsyncInitializationPolicy( { } -AsyncInitializationPolicy::~AsyncInitializationPolicy() -{ -} +AsyncInitializationPolicy::~AsyncInitializationPolicy() = default; void AsyncInitializationPolicy::initSynchronous() @@ -74,7 +72,7 @@ AsyncInitializationPolicy::select(mbus::RoutingContext& context) } { - vespalib::MonitorGuard lock(_lock); + std::lock_guard lock(_lock); if (_state == State::NOT_STARTED || _state == State::FAILED) { // Only 1 task may be queued to the executor at any point in time. @@ -88,7 +86,7 @@ AsyncInitializationPolicy::select(mbus::RoutingContext& context) } if (_state != State::DONE) { - mbus::Reply::UP reply(new mbus::EmptyReply()); + auto reply = std::make_unique<mbus::EmptyReply>(); reply->addError(currentPolicyInitError()); context.setReply(std::move(reply)); return; @@ -117,7 +115,7 @@ AsyncInitializationPolicy::Task::run() using State = AsyncInitializationPolicy::State; - vespalib::MonitorGuard lock(_owner._lock); + std::lock_guard lock(_owner._lock); _owner._error = error; _owner._state = error.empty() ? State::DONE : State::FAILED; } diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.h index f056bb3b329..0e30da8e7c8 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/asyncinitializationpolicy.h @@ -5,15 +5,15 @@ #include <vespa/messagebus/error.h> #include <vespa/vespalib/util/executor.h> #include <vespa/documentapi/common.h> -#include <vespa/vespalib/util/sync.h> #include <map> +#include <mutex> namespace documentapi { class AsyncInitializationPolicy : public mbus::IRoutingPolicy { public: AsyncInitializationPolicy(const std::map<string, string>& parameters); - virtual ~AsyncInitializationPolicy(); + ~AsyncInitializationPolicy() override; static std::map<string, string> parse(string parameters); @@ -64,7 +64,7 @@ private: friend class Task; std::unique_ptr<vespalib::Executor> _executor; - vespalib::Monitor _lock; + std::mutex _lock; enum class State { NOT_STARTED, diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h b/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h index 61c79eb0a41..865709daf7f 100644 --- a/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h +++ b/documentapi/src/vespa/documentapi/messagebus/policies/externslobrokpolicy.h @@ -33,7 +33,7 @@ protected: public: ExternSlobrokPolicy(const std::map<string, string>& params); - ~ExternSlobrokPolicy(); + ~ExternSlobrokPolicy() override; /** * @return a pointer to the slobrok mirror owned by this policy, if any. diff --git a/fnet/src/tests/connect/connect_test.cpp b/fnet/src/tests/connect/connect_test.cpp index 62000efb682..3fe7b5b7614 100644 --- a/fnet/src/tests/connect/connect_test.cpp +++ b/fnet/src/tests/connect/connect_test.cpp @@ -4,7 +4,6 @@ #include <vespa/fnet/fnet.h> #include <vespa/vespalib/net/server_socket.h> #include <vespa/vespalib/net/crypto_engine.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/stringfmt.h> using namespace vespalib; diff --git a/fnet/src/vespa/fnet/transport_thread.cpp b/fnet/src/vespa/fnet/transport_thread.cpp index 158524d1214..a20de880f15 100644 --- a/fnet/src/vespa/fnet/transport_thread.cpp +++ b/fnet/src/vespa/fnet/transport_thread.cpp @@ -7,7 +7,6 @@ #include "connector.h" #include "connection.h" #include "transport.h" -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/net/socket_spec.h> #include <vespa/vespalib/net/server_socket.h> #include <csignal> diff --git a/messagebus/src/vespa/messagebus/network/rpctargetpool.h b/messagebus/src/vespa/messagebus/network/rpctargetpool.h index d47fd977356..bc9e1a4b19f 100644 --- a/messagebus/src/vespa/messagebus/network/rpctargetpool.h +++ b/messagebus/src/vespa/messagebus/network/rpctargetpool.h @@ -4,7 +4,6 @@ #include "rpcserviceaddress.h" #include "rpctarget.h" #include <vespa/messagebus/itimer.h> -#include <vespa/vespalib/util/sync.h> #include <map> class FRT_Supervisor; diff --git a/messagebus/src/vespa/messagebus/routing/resender.h b/messagebus/src/vespa/messagebus/routing/resender.h index 68b49cde606..f70fd57265c 100644 --- a/messagebus/src/vespa/messagebus/routing/resender.h +++ b/messagebus/src/vespa/messagebus/routing/resender.h @@ -4,7 +4,6 @@ #include "iretrypolicy.h" #include <vespa/messagebus/queue.h> #include <vespa/messagebus/reply.h> -#include <vespa/vespalib/util/sync.h> #include <queue> #include <vector> diff --git a/messagebus/src/vespa/messagebus/routing/routingnode.h b/messagebus/src/vespa/messagebus/routing/routingnode.h index 3902e4ef699..2f82eb0ff92 100644 --- a/messagebus/src/vespa/messagebus/routing/routingnode.h +++ b/messagebus/src/vespa/messagebus/routing/routingnode.h @@ -12,7 +12,6 @@ #include <vespa/messagebus/messagebus.h> #include <vespa/messagebus/network/iserviceaddress.h> #include <vespa/messagebus/reply.h> -#include <vespa/vespalib/util/sync.h> #include <vector> #include <map> diff --git a/searchlib/src/vespa/searchlib/docstore/lid_info.h b/searchlib/src/vespa/searchlib/docstore/lid_info.h index 56629e4988a..152246631a7 100644 --- a/searchlib/src/vespa/searchlib/docstore/lid_info.h +++ b/searchlib/src/vespa/searchlib/docstore/lid_info.h @@ -3,9 +3,9 @@ #pragma once #include <vespa/vespalib/util/generationhandler.h> -#include <vespa/vespalib/util/sync.h> #include <limits> #include <vector> +#include <mutex> namespace search { diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp index c3f4214fb60..1671b6cae69 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp @@ -11,7 +11,6 @@ namespace search::docstore { using vespalib::ConstBufferRef; -using vespalib::LockGuard; using vespalib::DataBuffer; using vespalib::alloc::Alloc; using vespalib::alloc::MemoryAllocator; diff --git a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h index 1c6dd58d585..cdbbd51ec77 100644 --- a/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/writeablefilechunk.h @@ -4,6 +4,7 @@ #include "filechunk.h" #include <vespa/vespalib/util/executor.h> +#include <vespa/vespalib/util/sync.h> #include <vespa/searchlib/transactionlog/syncproxy.h> #include <vespa/fastos/file.h> #include <map> diff --git a/searchlib/src/vespa/searchlib/transactionlog/session.h b/searchlib/src/vespa/searchlib/transactionlog/session.h index ddbe218ed4e..ea78907da90 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/session.h +++ b/searchlib/src/vespa/searchlib/transactionlog/session.h @@ -3,7 +3,6 @@ #include "common.h" #include <vespa/vespalib/util/executor.h> -#include <vespa/vespalib/util/sync.h> #include <chrono> #include <deque> #include <atomic> diff --git a/staging_vespalib/src/vespa/vespalib/stllike/cache.h b/staging_vespalib/src/vespa/vespalib/stllike/cache.h index d0491e4d246..798fdb70138 100644 --- a/staging_vespalib/src/vespa/vespalib/stllike/cache.h +++ b/staging_vespalib/src/vespa/vespalib/stllike/cache.h @@ -2,7 +2,6 @@ #pragma once #include <vespa/vespalib/stllike/lrucache_map.h> -#include <vespa/vespalib/util/sync.h> #include <atomic> namespace vespalib { @@ -134,7 +133,7 @@ private: */ bool removeOldest(const value_type & v) override; size_t calcSize(const K & k, const V & v) const { return sizeof(value_type) + _sizeK(k) + _sizeV(v); } - vespalib::Lock & getLock(const K & k) { + std::mutex & getLock(const K & k) { size_t h(_hasher(k)); return _addLocks[h%(sizeof(_addLocks)/sizeof(_addLocks[0]))]; } @@ -156,7 +155,7 @@ private: BackingStore & _store; mutable std::mutex _hashLock; /// Striped locks that can be used for having a locked access to the backing store. - vespalib::Lock _addLocks[113]; + std::mutex _addLocks[113]; }; } diff --git a/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp b/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp index 652abc6672b..719169ba747 100644 --- a/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp +++ b/staging_vespalib/src/vespa/vespalib/stllike/cache.hpp @@ -92,7 +92,7 @@ cache<P>::read(const K & key) } } - vespalib::LockGuard storeGuard(getLock(key)); + std::lock_guard storeGuard(getLock(key)); { std::lock_guard guard(_hashLock); if (Lru::hasKey(key)) { @@ -118,7 +118,7 @@ void cache<P>::write(const K & key, V value) { size_t newSize = calcSize(key, value); - vespalib::LockGuard storeGuard(getLock(key)); + std::lock_guard storeGuard(getLock(key)); { std::lock_guard guard(_hashLock); if (Lru::hasKey(key)) { @@ -140,7 +140,7 @@ template< typename P > void cache<P>::erase(const K & key) { - vespalib::LockGuard storeGuard(getLock(key)); + std::lock_guard storeGuard(getLock(key)); invalidate(key); _store.erase(key); } diff --git a/storage/src/vespa/storage/distributor/operations/external/statbucketlistoperation.h b/storage/src/vespa/storage/distributor/operations/external/statbucketlistoperation.h index c977ea78f67..aa38a0d2319 100644 --- a/storage/src/vespa/storage/distributor/operations/external/statbucketlistoperation.h +++ b/storage/src/vespa/storage/distributor/operations/external/statbucketlistoperation.h @@ -4,7 +4,6 @@ #include <vespa/vespalib/util/hdr_abort.h> #include <vespa/storage/distributor/operations/operation.h> #include <vespa/storage/bucketdb/bucketdatabase.h> -#include <vespa/vespalib/util/sync.h> namespace storage { diff --git a/storage/src/vespa/storage/distributor/sentmessagemap.h b/storage/src/vespa/storage/distributor/sentmessagemap.h index 405e59f7b31..e84920b88d7 100644 --- a/storage/src/vespa/storage/distributor/sentmessagemap.h +++ b/storage/src/vespa/storage/distributor/sentmessagemap.h @@ -1,14 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/vespalib/util/sync.h> #include <map> #include <vespa/storageapi/messageapi/storagemessage.h> -namespace storage -{ - -namespace distributor { +namespace storage::distributor { class Operation; @@ -32,6 +28,3 @@ private: }; } - -} - diff --git a/storage/src/vespa/storage/storageserver/priorityconverter.h b/storage/src/vespa/storage/storageserver/priorityconverter.h index 3a4950fdb31..08669c672d5 100644 --- a/storage/src/vespa/storage/storageserver/priorityconverter.h +++ b/storage/src/vespa/storage/storageserver/priorityconverter.h @@ -5,9 +5,9 @@ #include <vespa/storage/config/config-stor-prioritymapping.h> #include <vespa/config/helper/configfetcher.h> #include <vespa/documentapi/messagebus/priority.h> -#include <vespa/vespalib/util/sync.h> #include <atomic> #include <array> +#include <mutex> namespace config {class ConfigUri; } diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp index 1f1a2c602de..0f5546a5510 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp +++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp @@ -4,7 +4,6 @@ #include <vespa/messagebus/routing/verbatimdirective.h> #include <vespa/vespalib/util/exceptions.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/stllike/hash_fun.h> #include <sstream> diff --git a/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp b/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp index c56a6fbb750..3178220654e 100644 --- a/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp +++ b/storageframework/src/vespa/storageframework/generic/thread/tickingthread.cpp @@ -2,6 +2,7 @@ #include "tickingthread.h" #include "threadpool.h" #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/util/sync.h> #include <cassert> namespace storage::framework { diff --git a/storageframework/src/vespa/storageframework/generic/thread/tickingthread.h b/storageframework/src/vespa/storageframework/generic/thread/tickingthread.h index 477c17b1cc3..1ed02d0f6fd 100644 --- a/storageframework/src/vespa/storageframework/generic/thread/tickingthread.h +++ b/storageframework/src/vespa/storageframework/generic/thread/tickingthread.h @@ -21,7 +21,6 @@ #include <memory> #include <vespa/storageframework/generic/clock/time.h> #include <vespa/vespalib/stllike/string.h> -#include <vespa/vespalib/util/sync.h> namespace storage::framework { diff --git a/vbench/src/apps/vbench/vbench.cpp b/vbench/src/apps/vbench/vbench.cpp index 61206c772e7..ab695f0b728 100644 --- a/vbench/src/apps/vbench/vbench.cpp +++ b/vbench/src/apps/vbench/vbench.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/util/signalhandler.h> #include <vespa/vespalib/util/programoptions.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/thread.h> #include <vespa/vespalib/util/runnable_pair.h> #include <vbench/vbench/vbench.h> diff --git a/vbench/src/tests/http_connection_pool/http_connection_pool_test.cpp b/vbench/src/tests/http_connection_pool/http_connection_pool_test.cpp index c0c5982d22b..08d44057dfc 100644 --- a/vbench/src/tests/http_connection_pool/http_connection_pool_test.cpp +++ b/vbench/src/tests/http_connection_pool/http_connection_pool_test.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/testapp.h> #include <vbench/test/all.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/net/crypto_engine.h> using namespace vbench; diff --git a/vbench/src/tests/time_queue/time_queue_test.cpp b/vbench/src/tests/time_queue/time_queue_test.cpp index 8b683f99127..5ce4feab747 100644 --- a/vbench/src/tests/time_queue/time_queue_test.cpp +++ b/vbench/src/tests/time_queue/time_queue_test.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/testapp.h> #include <vbench/test/all.h> -#include <vespa/vespalib/util/sync.h> using namespace vbench; diff --git a/vbench/src/vbench/vbench/request_scheduler.h b/vbench/src/vbench/vbench/request_scheduler.h index 2f9e9177c53..69be0bba6ca 100644 --- a/vbench/src/vbench/vbench/request_scheduler.h +++ b/vbench/src/vbench/vbench/request_scheduler.h @@ -7,7 +7,6 @@ #include <vbench/core/time_queue.h> #include <vbench/core/dispatcher.h> #include <vbench/core/handler_thread.h> -#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/active.h> namespace vbench { 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; |