6 namespace honey {
namespace lockfree
16 class FreeList : mt::NoCopy
29 szt capacity()
const {
return _pool._buckets[0]->_blockCount; }
32 T*
alloc() {
return static_cast<T*
>(_pool.
alloc(
sizeof(T))); }
34 template<
class... Args>
35 T*
construct(Args&&... args) {
return new (
alloc()) T{forward<Args>(args)...}; }
43 Handle
handle(T* ptr)
const {
return ptr ? MemPool::Bucket::blockHeader(reinterpret_cast<uint8*>(ptr))->handle :
nullptr; }
45 T*
deref(Handle
handle)
const {
return reinterpret_cast<T*
>(MemPool::Bucket::blockData(_pool._buckets[0]->deref(handle))); }
Enables blocks to be referenced via index rather than pointer so that they can include a tag while st...
Definition: Pool.h:75
FreeList(szt capacity=0)
Definition: FreeList.h:24
Holds block handle and tag to prevent lock-free ABA issues.
Definition: Pool.h:95
Node * construct(Args &&...args)
Construct object and remove from free list.
Definition: FreeList.h:35
void reserve(szt capacity)
Ensure that enough storage is allocated for a number of objects.
Definition: FreeList.h:27
void free(void *ptr_)
Free a memory block allocated from the pool.
Definition: Pool.cpp:261
void free(Node *ptr)
Add object to free list without destroying it.
Definition: FreeList.h:38
MemPool::Bucket::TaggedHandle TaggedHandle
Definition: FreeList.h:22
Definition: FreeList.h:52
Lock-free freelist, allocates re-usable objects and provides automatic storage expansion for concurre...
Definition: Pool.h:10
void * alloc(szt size, uint8 align=1, const char *srcFile=nullptr, int srcLine=0)
Allocate a size bytes block of memory at byte boundary align. alignment must be a power of two...
Definition: Pool.cpp:249
FreeListAllocator(const FreeListAllocator< U > &)
Definition: FreeList.h:57
friend class FreeListAllocator
Definition: FreeList.h:18
Node value_type
Definition: FreeList.h:20
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
MemPool allocator.
Definition: Pool.h:288
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
void destroy(Node *ptr)
Destroy object and add to free list.
Definition: FreeList.h:40
Memory pool.
Definition: Pool.h:29
Node * alloc()
Remove object from free list without constructing it.
Definition: FreeList.h:32
szt capacity() const
The number of objects for which storage is allocated.
Definition: FreeList.h:29
Node * deref(Handle handle) const
Get object from compressed handle.
Definition: FreeList.h:45
MemPool::Bucket::Handle Handle
Definition: FreeList.h:21
Handle handle(Node *ptr) const
Get compressed handle for object.
Definition: FreeList.h:43
Global Honeycomb namespace.
MemPool & pool()
Definition: FreeList.h:59