From 1a3d9dc9ea0ed3b250d7eba77a4952e18b1a96ff Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 24 May 2023 16:53:34 +0000 Subject: Inline small simple methods --- .../src/vespa/vespalib/util/generationhandler.cpp | 36 ---------------------- .../src/vespa/vespalib/util/generationhandler.h | 28 +++++++++++------ 2 files changed, 18 insertions(+), 46 deletions(-) (limited to 'vespalib/src') diff --git a/vespalib/src/vespa/vespalib/util/generationhandler.cpp b/vespalib/src/vespa/vespalib/util/generationhandler.cpp index d64779e5f0b..8edf0d6fae4 100644 --- a/vespalib/src/vespa/vespalib/util/generationhandler.cpp +++ b/vespalib/src/vespa/vespalib/util/generationhandler.cpp @@ -31,11 +31,6 @@ GenerationHandler::GenerationHold::setInvalid() noexcept { return _refCount.compare_exchange_strong(refs, 1, std::memory_order_seq_cst); } -void -GenerationHandler::GenerationHold::release() noexcept { - _refCount.fetch_sub(2); -} - GenerationHandler::GenerationHold * GenerationHandler::GenerationHold::acquire() noexcept { if (valid(_refCount.fetch_add(2))) { @@ -58,37 +53,6 @@ GenerationHandler::GenerationHold::copy(GenerationHold *self) noexcept { } } -uint32_t -GenerationHandler::GenerationHold::getRefCount() const noexcept { - return _refCount / 2; -} - -GenerationHandler::Guard::Guard() noexcept - : _hold(nullptr) -{ -} - -GenerationHandler::Guard::Guard(GenerationHold *hold) noexcept - : _hold(hold->acquire()) -{ -} - -GenerationHandler::Guard::~Guard() -{ - cleanup(); -} - -GenerationHandler::Guard::Guard(const Guard & rhs) noexcept - : _hold(GenerationHold::copy(rhs._hold)) -{ -} - -GenerationHandler::Guard::Guard(Guard &&rhs) noexcept - : _hold(rhs._hold) -{ - rhs._hold = nullptr; -} - GenerationHandler::Guard & GenerationHandler::Guard::operator=(const Guard & rhs) noexcept { diff --git a/vespalib/src/vespa/vespalib/util/generationhandler.h b/vespalib/src/vespa/vespalib/util/generationhandler.h index 5aaf342564c..b346b1fa4e2 100644 --- a/vespalib/src/vespa/vespalib/util/generationhandler.h +++ b/vespalib/src/vespa/vespalib/util/generationhandler.h @@ -38,10 +38,14 @@ public: void setValid() noexcept; bool setInvalid() noexcept; - void release() noexcept; + void release() noexcept { + _refCount.fetch_sub(2); + } GenerationHold *acquire() noexcept; static GenerationHold *copy(GenerationHold *self) noexcept; - uint32_t getRefCount() const noexcept; + uint32_t getRefCount() const noexcept { + return _refCount.load(std::memory_order_relaxed) / 2; + } }; /** @@ -57,11 +61,15 @@ public: } } public: - Guard() noexcept; - Guard(GenerationHold *hold) noexcept; // hold is never nullptr - ~Guard(); - Guard(const Guard & rhs) noexcept; - Guard(Guard &&rhs) noexcept; + Guard() noexcept : _hold(nullptr) { } + Guard(GenerationHold *hold) noexcept : _hold(hold->acquire()) { } // hold is never nullptr + ~Guard() { cleanup(); } + Guard(const Guard & rhs) noexcept : _hold(GenerationHold::copy(rhs._hold)) { } + Guard(Guard &&rhs) noexcept + : _hold(rhs._hold) + { + rhs._hold = nullptr; + } Guard & operator=(const Guard & rhs) noexcept; Guard & operator=(Guard &&rhs) noexcept; @@ -75,9 +83,9 @@ private: std::atomic _generation; std::atomic _oldest_used_generation; std::atomic _last; // Points to "current generation" entry - GenerationHold *_first; // Points to "firstUsedGeneration" entry - GenerationHold *_free; // List of free entries - uint32_t _numHolds; // Number of allocated generation hold entries + GenerationHold *_first; // Points to "firstUsedGeneration" entry + GenerationHold *_free; // List of free entries + uint32_t _numHolds; // Number of allocated generation hold entries void set_generation(generation_t generation) noexcept { _generation.store(generation, std::memory_order_relaxed); } -- cgit v1.2.3