summaryrefslogtreecommitdiffstats
path: root/vespamalloc
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-02-15 11:56:42 +0100
committerGitHub <noreply@github.com>2023-02-15 11:56:42 +0100
commit96f1b6d5ec1bbb883b817c0775411256e7f00474 (patch)
tree7f3d07699ae2815753dc829a3fccb54a4cbc12f5 /vespamalloc
parenta9486b78d445db8279169a8cb47575471ca3232d (diff)
parente31f85cdebf812c3f3377e561c45b9dfe570fdd5 (diff)
Merge pull request #26043 from vespa-engine/balder/use-correct-implementation
Balder/use correct implementation
Diffstat (limited to 'vespamalloc')
-rw-r--r--vespamalloc/src/vespamalloc/malloc/allocchunk.cpp8
-rw-r--r--vespamalloc/src/vespamalloc/malloc/allocchunk.h35
2 files changed, 21 insertions, 22 deletions
diff --git a/vespamalloc/src/vespamalloc/malloc/allocchunk.cpp b/vespamalloc/src/vespamalloc/malloc/allocchunk.cpp
index e76f737166d..daef496d3a7 100644
--- a/vespamalloc/src/vespamalloc/malloc/allocchunk.cpp
+++ b/vespamalloc/src/vespamalloc/malloc/allocchunk.cpp
@@ -4,14 +4,14 @@
namespace vespamalloc {
-void AFListBase::linkInList(AtomicHeadPtr & head, AFListBase * list)
+void AFListBase::linkInList(AtomicHeadPtr & head, AFListBase * list) noexcept
{
AFListBase * tail;
for (tail = list; tail->_next != nullptr ;tail = tail->_next) { }
linkIn(head, list, tail);
}
-void AFListBase::linkIn(AtomicHeadPtr & head, AFListBase * csl, AFListBase * tail)
+void AFListBase::linkIn(AtomicHeadPtr & head, AFListBase * csl, AFListBase * tail) noexcept
{
HeadPtr oldHead = head.load(std::memory_order_relaxed);
HeadPtr newHead(csl, oldHead._tag + 1);
@@ -22,10 +22,10 @@ void AFListBase::linkIn(AtomicHeadPtr & head, AFListBase * csl, AFListBase * tai
}
}
-AFListBase * AFListBase::linkOut(AtomicHeadPtr & head)
+AFListBase * AFListBase::linkOut(AtomicHeadPtr & head) noexcept
{
HeadPtr oldHead = head.load(std::memory_order_relaxed);
- AFListBase *csl = static_cast<AFListBase *>(oldHead._ptr);
+ auto *csl = static_cast<AFListBase *>(oldHead._ptr);
if (csl == nullptr) {
return nullptr;
}
diff --git a/vespamalloc/src/vespamalloc/malloc/allocchunk.h b/vespamalloc/src/vespamalloc/malloc/allocchunk.h
index 7df8e12b470..91e05c38658 100644
--- a/vespamalloc/src/vespamalloc/malloc/allocchunk.h
+++ b/vespamalloc/src/vespamalloc/malloc/allocchunk.h
@@ -74,16 +74,15 @@ class AFListBase
{
public:
using HeadPtr = TaggedPtr;
- using AtomicHeadPtr = std::atomic<TaggedPtr>;
+ using AtomicHeadPtr = AtomicTaggedPtr;
- AFListBase() : _next(nullptr) { }
- void setNext(AFListBase * csl) { _next = csl; }
- static void init();
- static void linkInList(AtomicHeadPtr & head, AFListBase * list);
- static void linkIn(AtomicHeadPtr & head, AFListBase * csl, AFListBase * tail);
+ AFListBase() noexcept : _next(nullptr) { }
+ void setNext(AFListBase * csl) noexcept { _next = csl; }
+ static void linkInList(AtomicHeadPtr & head, AFListBase * list) noexcept;
+ static void linkIn(AtomicHeadPtr & head, AFListBase * csl, AFListBase * tail) noexcept;
protected:
- AFListBase * getNext() { return _next; }
- static AFListBase * linkOut(AtomicHeadPtr & head);
+ AFListBase * getNext() noexcept { return _next; }
+ static AFListBase * linkOut(AtomicHeadPtr & head) noexcept;
private:
AFListBase *_next;
};
@@ -94,24 +93,24 @@ class AFList : public AFListBase
public:
typedef size_t CountT;
enum { NumBlocks = 126 };
- AFList() : _count(0) { }
- CountT count() const { return _count; }
- void add(MemBlockPtrT & ptr) {
+ AFList() noexcept : _count(0) { }
+ [[nodiscard]] CountT count() const noexcept { return _count; }
+ void add(MemBlockPtrT & ptr) noexcept {
ptr.free();
PARANOID_CHECK2( if (full()) { *(int*)0=0; });
_memBlockList[_count++] = ptr;
}
- void sub(MemBlockPtrT & mem) {
+ void sub(MemBlockPtrT & mem) noexcept {
if (empty()) {
return;
}
mem = _memBlockList[--_count];
}
- bool empty() const { return (_count == 0); }
- bool full() const { return (_count == NumBlocks); }
- size_t fill(void * mem, SizeClassT sc, size_t blocksPerChunk = NumBlocks);
- AFList * getNext() { return static_cast<AFList *>(AFListBase::getNext()); }
- static AFList * linkOut(AtomicHeadPtr & head) {
+ [[nodiscard]] bool empty() const noexcept { return (_count == 0); }
+ [[nodiscard]] bool full() const noexcept { return (_count == NumBlocks); }
+ size_t fill(void * mem, SizeClassT sc, size_t blocksPerChunk = NumBlocks) noexcept;
+ AFList * getNext() noexcept { return static_cast<AFList *>(AFListBase::getNext()); }
+ static AFList * linkOut(AtomicHeadPtr & head) noexcept {
return static_cast<AFList *>(AFListBase::linkOut(head));
}
private:
@@ -121,7 +120,7 @@ private:
template <typename MemBlockPtrT>
-size_t AFList<MemBlockPtrT>::fill(void * mem, SizeClassT sc, size_t blocksPerChunk)
+size_t AFList<MemBlockPtrT>::fill(void * mem, SizeClassT sc, size_t blocksPerChunk) noexcept
{
size_t sz = MemBlockPtrT::classSize(sc);
int retval(std::max(0, int(blocksPerChunk-_count)));