diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-15 08:24:37 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-15 08:24:37 +0000 |
commit | 72b64efd251413e8313ded6e2ca89abaac755b4f (patch) | |
tree | 3feb8fb62afa86fdd13f8678d2c5246b8e6af5e8 /vespamalloc | |
parent | c5fe5b6be07e57115cd72738a5afd928b0df60ef (diff) |
Add noexcept and nodiscard
Diffstat (limited to 'vespamalloc')
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/allocchunk.cpp | 8 | ||||
-rw-r--r-- | vespamalloc/src/vespamalloc/malloc/allocchunk.h | 33 |
2 files changed, 20 insertions, 21 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..726b0332aea 100644 --- a/vespamalloc/src/vespamalloc/malloc/allocchunk.h +++ b/vespamalloc/src/vespamalloc/malloc/allocchunk.h @@ -76,14 +76,13 @@ public: using HeadPtr = TaggedPtr; using AtomicHeadPtr = std::atomic<TaggedPtr>; - 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))); |