Class ThreadSafeFreelist¶
Defined in File pool_allocator.hpp
Nested Relationships¶
Class Documentation¶
-
class
ripple
::
ThreadSafeFreelist
¶ This type is a thread-safe freelist implementation.
It’s lock-free, and uses atomics to control access to the nodes in the freelist.
Use this only when data needs to be shared across threads, and even so, compare the performance against other allocators with a locking policy, such as the single-threaded Freelist with a spinlock.
Benchmark this against other options.
Also consider using thread-local freelists with a common arena, with this as a fallback.
Public Functions
-
ThreadSafeFreelist
() noexcept = default¶ Default constructor.
-
ThreadSafeFreelist
(const void *start, const void *end, size_t element_size, size_t alignment) noexcept¶ Constructor to initialize the freelist with the
start
andend
of the arena from which elements can be stored.- Parameters
start
: The start of the arena.end
: The end of the arena.element_size
: The size of the elements in the freelist.alignment
: The alignment of the elements.
-
ThreadSafeFreelist
(ThreadSafeFreelist &&other) noexcept¶ Move constructor to move
other
to this freelist.- Parameters
other
: The other freelist to move.
-
auto
operator=
(ThreadSafeFreelist &&other) noexcept -> ThreadSafeFreelist&¶ Move assignment to move other to this freelist.
- Parameters
other
: The other freelist to move.
-
ThreadSafeFreelist
(const ThreadSafeFreelist&) = delete¶ Copy constructor deleted since the freelist can’t be copied.
-
auto
operator=
(const ThreadSafeFreelist&) = delete¶ Copy assignment deleted since the freelist can’t be copied.
-
auto
pop_front
() noexcept -> void*¶ Pops the most recently added element from the list, and returns it.
If there are no elements left in the list, this returns a nullptr.
-
auto
push_front
(void *ptr) noexcept -> void¶ Pushes the ptr onto the front of the free list.
- Parameters
ptr
: The pointer to push onto the front.
-