cds
2.3.2
|
Lock-free free list. More...
#include <cds/intrusive/free_list.h>
Data Structures | |
struct | node |
Free list node. More... | |
Public Member Functions | |
FreeList () | |
Creates empty free list. | |
~FreeList () | |
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... | |
Lock-free free list.
Free list is a helper class intended for reusing objects instead of freeing them completely; this avoids the overhead of malloc()
, and also avoids its worst-case behavior of taking an operating system lock. So, the free list can be considered as a specialized allocator for objects of some type.
The algorithm is taken from this article. The algo does not require any SMR like Hazard Pointer to prevent ABA problem.
There is tagged pointers variant of free list for processors with double-width CAS support.
How to use
|
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.