diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-02-16 22:23:07 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-02-16 22:23:07 +0100 |
commit | c692a82c08b1f530807e5910bbadc270c5537c31 (patch) | |
tree | 088647e27eab2129b9636a579f7e2e2618e64eec /vespalib | |
parent | afc50121bb3dc97082024d3facfb9510ac21c59c (diff) |
Detect dangling shared operation throttler token when using no limits operation throttler.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp b/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp index 1df5f85bb6b..f5a1c117cc8 100644 --- a/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp +++ b/vespalib/src/vespa/vespalib/util/shared_operation_throttler.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "shared_operation_throttler.h" +#include <atomic> #include <condition_variable> #include <cassert> #include <functional> @@ -11,21 +12,32 @@ namespace { class NoLimitsOperationThrottler final : public SharedOperationThrottler { public: - ~NoLimitsOperationThrottler() override = default; + NoLimitsOperationThrottler() + : SharedOperationThrottler(), + _refs(0u) + { + } + ~NoLimitsOperationThrottler() override { + assert(_refs.load(std::memory_order_acquire) == 0u); + } Token blocking_acquire_one() noexcept override { + ++_refs; return Token(this, TokenCtorTag{}); } Token blocking_acquire_one(vespalib::duration) noexcept override { + ++_refs; return Token(this, TokenCtorTag{}); } Token try_acquire_one() noexcept override { + ++_refs; return Token(this, TokenCtorTag{}); } uint32_t current_window_size() const noexcept override { return 0; } uint32_t waiting_threads() const noexcept override { return 0; } void reconfigure_dynamic_throttling(const DynamicThrottleParams&) noexcept override { /* no-op */ } private: - void release_one() noexcept override { /* no-op */ } + void release_one() noexcept override { --_refs; } + std::atomic<uint32_t> _refs; }; /** |