cds
2.3.2
|
Cached free list. More...
#include <cds/intrusive/free_list_cached.h>
Public Types | |
typedef FreeList | free_list_type |
Undelying free-list type. | |
typedef free_list_type::node | node |
Free-list node. | |
Public Member Functions | |
CachedFreeList () | |
Creates empty free list. | |
~CachedFreeList () | |
Destroys the free list. Free-list must be empty. More... | |
void | put (node *pNode) |
Puts pNode to the free list. | |
node * | get () |
Gets a node from the free list. If the list is empty, returns nullptr . | |
bool | empty () const |
Checks whether the free list is empty. | |
template<typename Disposer > | |
void | clear (Disposer disp) |
Clears the free list (not atomic) More... | |
Static Public Attributes | |
static size_t const | c_cache_size = CacheSize |
Cache size. | |
static unsigned const | c_padding = Padding |
Cache element padding. | |
Cached free list.
The class that is a wrapper over other FreeList
contains a small cache of free elements. Before placing a new item into underlying FreeList
the cached free-list tryes to put that item into the cache if its corresponding slot is empty. The slot is calculated by current thread id:
When getting the free-list checks the corresponding cache slot. If it is not empty, its contents is returned.
In some cases such simple algorithm significantly reduces FreeList
contention.
Template parameters:
FreeList
- a free-list implementation: FreeList
, TaggedFreeList
CacheSize
- size of cache, a small power-of-two number, default is 16Padding
- padding of cache elements for solving false sharing, default is cds::c_nCacheLineSize
|
inline |
Destroys the free list. Free-list must be empty.
clear()
with an appropriate disposer.
|
inline |
Clears the free list (not atomic)
For each element disp
disposer is called to free memory. The Disposer
interface:
This method must be explicitly called before the free list destructor.