cds  2.3.2
cds::intrusive::TaggedFreeList Class Reference

Lock-free free list based on tagged pointers (required double-width CAS) More...

#include <cds/intrusive/free_list_tagged.h>

Data Structures

struct  node
 

Public Member Functions

 TaggedFreeList ()
 Creates empty free-list.
 
 ~TaggedFreeList ()
 Destroys the free list. Free-list must be empty. More...
 
void put (node *pNode)
 Puts pNode to the free list.
 
nodeget ()
 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...
 

Detailed Description

Lock-free free list based on tagged pointers (required double-width CAS)

This variant of FreeList is intended for processor architectures that support double-width CAS. It uses tagged pointer technique to solve ABA problem.

How to use

#include <cds/intrusive/free_list_tagged.h>
// Your struct should be derived from TaggedFreeList::node
{
// Foo fields
};
// Simplified Foo allocator
class FooAllocator
{
public:
// free-list clear() must be explicitly called before destroying the free-list object
~FooAllocator()
{
m_FreeList.clear( []( freelist_node * p ) { delete static_cast<Foo *>( p ); });
}
Foo * alloc()
{
freelist_node * p = m_FreeList.get();
if ( p )
return static_cast<Foo *>( p );
return new Foo;
};
void dealloc( Foo * p )
{
m_FreeList.put( static_cast<freelist_node *>( p ));
};
private:
typedef cds::intrusive::TaggedFreeList::node freelist_node;
};

Constructor & Destructor Documentation

◆ ~TaggedFreeList()

cds::intrusive::TaggedFreeList::~TaggedFreeList ( )
inline

Destroys the free list. Free-list must be empty.

Warning
dtor does not free elements of the list. To free elements you should manually call clear() with an appropriate disposer.

Member Function Documentation

◆ clear()

template<typename Disposer >
void cds::intrusive::TaggedFreeList::clear ( Disposer  disp)
inline

Clears the free list (not atomic)

For each element disp disposer is called to free memory. The Disposer interface:

struct disposer
{
void operator()( FreeList::node * node );
};

This method must be explicitly called before the free list destructor.


The documentation for this class was generated from the following file:

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:39 by Doxygen 1.8.13