diff options
Diffstat (limited to 'vespalib/src/vespa/vespalib/util/generationholder.cpp')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/generationholder.cpp | 55 |
1 files changed, 2 insertions, 53 deletions
diff --git a/vespalib/src/vespa/vespalib/util/generationholder.cpp b/vespalib/src/vespa/vespalib/util/generationholder.cpp index f2b10ff3af1..5f31f610c68 100644 --- a/vespalib/src/vespa/vespalib/util/generationholder.cpp +++ b/vespalib/src/vespa/vespalib/util/generationholder.cpp @@ -1,66 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "generationholder.h" -#include <cassert> +#include "generation_hold_list.hpp" namespace vespalib { GenerationHeldBase::~GenerationHeldBase() = default; GenerationHolder::GenerationHolder() - : _hold1List(), - _hold2List(), - _heldBytes(0) -{ } - -GenerationHolder::~GenerationHolder() -{ - assert(_hold1List.empty()); - assert(_hold2List.empty()); - assert(getHeldBytes() == 0); -} - -void -GenerationHolder::hold(GenerationHeldBase::UP data) -{ - _hold1List.push_back(std::move(data)); - _heldBytes.store(getHeldBytes() + _hold1List.back()->byte_size(), std::memory_order_relaxed); -} - -void -GenerationHolder::transferHoldListsSlow(generation_t generation) -{ - HoldList::iterator it(_hold1List.begin()); - HoldList::iterator ite(_hold1List.end()); - HoldList &hold2List = _hold2List; - for (; it != ite; ++it) { - assert((*it)->_generation == 0u); - (*it)->_generation = generation; - hold2List.push_back(std::move(*it)); - } - _hold1List.clear(); -} - -void -GenerationHolder::trimHoldListsSlow(generation_t usedGen) -{ - for (;;) { - if (_hold2List.empty()) - break; - GenerationHeldBase &first = *_hold2List.front(); - if (static_cast<sgeneration_t>(first._generation - usedGen) >= 0) - break; - _heldBytes.store(getHeldBytes() - first.byte_size(), std::memory_order_relaxed); - _hold2List.erase(_hold2List.begin()); - } -} - -void -GenerationHolder::clearHoldLists() + : GenerationHoldList<GenerationHeldBase::UP, true, false>() { - _hold1List.clear(); - _hold2List.clear(); - _heldBytes = 0; } } |