Lock-free free list. More...
|Free list node. More...|
|Creates empty free list. |
|Destroys the free list. Free-list must be empty. More...|
|void||put (node *pNode)|
|node *||get ()|
|Gets a node from the free list. If the list is empty, returns |
|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
Destroys the free list. Free-list must be empty.
clear()with an appropriate disposer.
Clears the free list (not atomic)
For each element
disp disposer is called to free memory. The
This method must be explicitly called before the free list destructor.