summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-02-13 15:50:12 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-02-13 15:50:12 +0000
commit8464c3678aac538a5bd1cc052681d419d6bfcac6 (patch)
treea5a8174ae86f8a73502378da7146f511d301c9ad /vespalib
parente2b02d3b7978d831293d88bc3c75c6582ef9418b (diff)
Less asserts in header files.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/datastore/allocator.hpp1
-rw-r--r--vespalib/src/vespa/vespalib/datastore/bufferstate.cpp9
-rw-r--r--vespalib/src/vespa/vespalib/datastore/bufferstate.h5
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/util/generationhandler.cpp66
-rw-r--r--vespalib/src/vespa/vespalib/util/generationhandler.h79
-rw-r--r--vespalib/src/vespa/vespalib/util/generationholder.cpp3
-rw-r--r--vespalib/src/vespa/vespalib/util/rcuvector.hpp1
8 files changed, 94 insertions, 74 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/allocator.hpp b/vespalib/src/vespa/vespalib/datastore/allocator.hpp
index 5f84d70e62f..e038f4a39d5 100644
--- a/vespalib/src/vespa/vespalib/datastore/allocator.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/allocator.hpp
@@ -4,6 +4,7 @@
#include "allocator.h"
#include "bufferstate.h"
+#include <cassert>
namespace vespalib::datastore {
diff --git a/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp b/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp
index 19b7cdf8181..76e706435cf 100644
--- a/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/bufferstate.cpp
@@ -2,6 +2,7 @@
#include "bufferstate.h"
#include <limits>
+#include <cassert>
using vespalib::alloc::Alloc;
using vespalib::alloc::MemoryAllocator;
@@ -13,7 +14,6 @@ BufferState::FreeListList::~FreeListList()
assert(_head == nullptr); // Owner should have disabled free lists
}
-
BufferState::BufferState()
: _usedElems(0),
_allocElems(0),
@@ -35,7 +35,6 @@ BufferState::BufferState()
{
}
-
BufferState::~BufferState()
{
assert(_state == FREE);
@@ -46,6 +45,12 @@ BufferState::~BufferState()
assert(isFreeListEmpty());
}
+void
+BufferState::decHoldElems(size_t value) {
+ assert(_holdElems >= value);
+ _holdElems -= value;
+}
+
namespace {
struct AllocResult {
diff --git a/vespalib/src/vespa/vespalib/datastore/bufferstate.h b/vespalib/src/vespa/vespalib/datastore/bufferstate.h
index ca9c6dd39ba..da03a150b40 100644
--- a/vespalib/src/vespa/vespalib/datastore/bufferstate.h
+++ b/vespalib/src/vespa/vespalib/datastore/bufferstate.h
@@ -176,10 +176,7 @@ public:
void incDeadElems(size_t value) { _deadElems += value; }
void incHoldElems(size_t value) { _holdElems += value; }
- void decHoldElems(size_t value) {
- assert(_holdElems >= value);
- _holdElems -= value;
- }
+ void decHoldElems(size_t value);
void incExtraUsedBytes(size_t value) { _extraUsedBytes += value; }
void incExtraHoldBytes(size_t value) {
_extraHoldBytes += value;
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
index ac6252bf514..4b1349d8801 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
@@ -3,6 +3,7 @@
#include "datastore.h"
#include <vespa/vespalib/util/array.hpp>
#include <limits>
+#include <cassert>
#include <vespa/log/log.h>
LOG_SETUP(".searchlib.datastore.datastorebase");
@@ -109,8 +110,7 @@ DataStoreBase::switchActiveBuffer(uint32_t typeId, size_t elemsNeeded)
}
}
if (!_states[activeBufferId].isFree()) {
- LOG(error, "did not find free buffer");
- abort();
+ LOG_ABORT("did not find free buffer");
}
onActive(activeBufferId, typeId, elemsNeeded);
_activeBufferIds[typeId] = activeBufferId;
diff --git a/vespalib/src/vespa/vespalib/util/generationhandler.cpp b/vespalib/src/vespa/vespalib/util/generationhandler.cpp
index 5fee6fa5c16..60195659eb9 100644
--- a/vespalib/src/vespa/vespalib/util/generationhandler.cpp
+++ b/vespalib/src/vespa/vespalib/util/generationhandler.cpp
@@ -1,9 +1,68 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "generationhandler.h"
+#include <cassert>
namespace vespalib {
+GenerationHandler::GenerationHold::GenerationHold(void)
+ : _refCount(1),
+ _generation(0),
+ _next(0)
+{ }
+
+GenerationHandler::GenerationHold::~GenerationHold() {
+ assert(getRefCount() == 0);
+}
+
+void
+GenerationHandler::GenerationHold::setValid() {
+ assert(!valid(_refCount));
+ _refCount.fetch_sub(1);
+}
+
+bool
+GenerationHandler::GenerationHold::setInvalid() {
+ uint32_t refs = _refCount;
+ assert(valid(refs));
+ if (refs != 0) {
+ return false;
+ }
+ return _refCount.compare_exchange_strong(refs, 1, std::memory_order_seq_cst);
+}
+
+void
+GenerationHandler::GenerationHold::release() {
+ _refCount.fetch_sub(2);
+}
+
+GenerationHandler::GenerationHold *
+GenerationHandler::GenerationHold::acquire() {
+ if (valid(_refCount.fetch_add(2))) {
+ return this;
+ } else {
+ release();
+ return nullptr;
+ }
+}
+
+GenerationHandler::GenerationHold *
+GenerationHandler::GenerationHold::copy(GenerationHold *self) {
+ if (self == nullptr) {
+ return nullptr;
+ } else {
+ uint32_t oldRefCount = self->_refCount.fetch_add(2);
+ (void) oldRefCount;
+ assert(valid(oldRefCount));
+ return self;
+ }
+}
+
+uint32_t
+GenerationHandler::GenerationHold::getRefCount() const {
+ return _refCount / 2;
+}
+
GenerationHandler::Guard::Guard()
: _hold(nullptr)
{
@@ -51,7 +110,6 @@ GenerationHandler::Guard::operator=(Guard &&rhs)
return *this;
}
-
void
GenerationHandler::updateFirstUsedGeneration()
{
@@ -73,7 +131,6 @@ GenerationHandler::updateFirstUsedGeneration()
_firstUsedGeneration = _first->_generation;
}
-
GenerationHandler::GenerationHandler()
: _generation(0),
_firstUsedGeneration(0),
@@ -88,10 +145,8 @@ GenerationHandler::GenerationHandler()
_last->setValid();
}
-
GenerationHandler::~GenerationHandler(void)
{
-
updateFirstUsedGeneration();
assert(_first == _last);
while (_free != nullptr) {
@@ -164,7 +219,6 @@ GenerationHandler::incGeneration()
updateFirstUsedGeneration();
}
-
uint32_t
GenerationHandler::getGenerationRefCount(generation_t gen) const
{
@@ -179,7 +233,6 @@ GenerationHandler::getGenerationRefCount(generation_t gen) const
return 0u;
}
-
uint64_t
GenerationHandler::getGenerationRefCount(void) const
{
@@ -190,7 +243,6 @@ GenerationHandler::getGenerationRefCount(void) const
return ret;
}
-
bool
GenerationHandler::hasReaders(void) const
{
diff --git a/vespalib/src/vespa/vespalib/util/generationhandler.h b/vespalib/src/vespa/vespalib/util/generationhandler.h
index d8af7f39c3e..1ba1baa7210 100644
--- a/vespalib/src/vespa/vespalib/util/generationhandler.h
+++ b/vespalib/src/vespa/vespalib/util/generationhandler.h
@@ -2,9 +2,8 @@
#pragma once
-#include <stdint.h>
+#include <cstdint>
#include <atomic>
-#include <cassert>
namespace vespalib {
@@ -16,8 +15,8 @@ namespace vespalib {
**/
class GenerationHandler {
public:
- typedef uint64_t generation_t;
- typedef int64_t sgeneration_t;
+ using generation_t = uint64_t;
+ using sgeneration_t = int64_t ;
/*
* This must be type stable memory, and cannot be freed before the
@@ -34,50 +33,15 @@ public:
generation_t _generation;
GenerationHold *_next; // next free element or next newer element.
- GenerationHold(void)
- : _refCount(1),
- _generation(0),
- _next(0)
- { }
+ GenerationHold();
+ ~GenerationHold();
- ~GenerationHold()
- {
- assert(getRefCount() == 0);
- }
-
- void setValid() {
- assert(!valid(_refCount));
- _refCount.fetch_sub(1);
- }
- bool setInvalid() {
- uint32_t refs = _refCount;
- assert(valid(refs));
- if (refs != 0) {
- return false;
- }
- return _refCount.compare_exchange_strong(refs, 1,
- std::memory_order_seq_cst);
- }
- void release() { _refCount.fetch_sub(2); }
- GenerationHold *acquire() {
- if (valid(_refCount.fetch_add(2))) {
- return this;
- } else {
- release();
- return nullptr;
- }
- }
- static GenerationHold *copy(GenerationHold *self) {
- if (self == nullptr) {
- return nullptr;
- } else {
- uint32_t oldRefCount = self->_refCount.fetch_add(2);
- (void) oldRefCount;
- assert(valid(oldRefCount));
- return self;
- }
- }
- uint32_t getRefCount() const { return _refCount / 2; }
+ void setValid();
+ bool setInvalid();
+ void release();
+ GenerationHold *acquire();
+ static GenerationHold *copy(GenerationHold *self);
+ uint32_t getRefCount() const;
};
/**
@@ -101,26 +65,25 @@ public:
Guard & operator=(const Guard & rhs);
Guard & operator=(Guard &&rhs);
- bool valid(void) const {
+ bool valid() const {
return _hold != nullptr;
}
generation_t getGeneration() const { return _hold->_generation; }
};
private:
- generation_t _generation;
- generation_t _firstUsedGeneration;
- 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
+ generation_t _generation;
+ generation_t _firstUsedGeneration;
+ 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
public:
/**
* Creates a new generation handler.
**/
GenerationHandler();
-
~GenerationHandler();
/**
@@ -156,7 +119,7 @@ public:
return _generation;
}
- generation_t getNextGeneration(void) const {
+ generation_t getNextGeneration() const {
return _generation + 1;
}
@@ -170,14 +133,14 @@ public:
* Returns the number of readers holding a generation guard.
* Should be called by the writer thread.
*/
- uint64_t getGenerationRefCount(void) const;
+ uint64_t getGenerationRefCount() const;
/**
* Returns true if we still have readers. False positives and
* negatives are possible if readers come and go while writer
* updates generations.
*/
- bool hasReaders(void) const;
+ bool hasReaders() const;
};
}
diff --git a/vespalib/src/vespa/vespalib/util/generationholder.cpp b/vespalib/src/vespa/vespalib/util/generationholder.cpp
index 1927adb9846..136b392971c 100644
--- a/vespalib/src/vespa/vespalib/util/generationholder.cpp
+++ b/vespalib/src/vespa/vespalib/util/generationholder.cpp
@@ -1,10 +1,11 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "generationholder.h"
+#include <cassert>
namespace vespalib {
-GenerationHeldBase::~GenerationHeldBase() { }
+GenerationHeldBase::~GenerationHeldBase() = default;
GenerationHolder::GenerationHolder()
: _hold1List(),
diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.hpp b/vespalib/src/vespa/vespalib/util/rcuvector.hpp
index f2324c654a4..8a5a828cfcb 100644
--- a/vespalib/src/vespa/vespalib/util/rcuvector.hpp
+++ b/vespalib/src/vespa/vespalib/util/rcuvector.hpp
@@ -4,6 +4,7 @@
#include "rcuvector.h"
#include <vespa/vespalib/util/array.hpp>
+#include <cassert>
namespace vespalib {