diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-05-24 16:53:34 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-05-24 16:53:34 +0000 |
commit | 1a3d9dc9ea0ed3b250d7eba77a4952e18b1a96ff (patch) | |
tree | 3fa0785797e2b977bc1c7ccdd1c8359fad40bb17 /vespalib | |
parent | c188bfa3d033adbb48f444ebbbe825037d9de8c8 (diff) |
Inline small simple methods
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/generationhandler.cpp | 36 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/generationhandler.h | 28 |
2 files changed, 18 insertions, 46 deletions
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_t> _generation; std::atomic<generation_t> _oldest_used_generation; std::atomic<GenerationHold *> _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); } |