cds  2.2.0
cds::intrusive::CachedFreeList< FreeList, CacheSize, Padding > Class Template Reference

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.
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...

Static Public Attributes

static size_t const c_cache_size = CacheSize
 Cache size.
static unsigned const c_padding = Padding
 Cache element padding.

Detailed Description

template<typename FreeList, size_t CacheSize = 16, unsigned Padding = cds::c_nCacheLineSize>
class cds::intrusive::CachedFreeList< FreeList, CacheSize, 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:

int slot = std::hash<std::thread::id>()( std::this_thread::get_id()) & (CacheSize - 1);

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 16
  • Padding - padding of cache elements for solving false sharing, default is cds::c_nCacheLineSize

Constructor & Destructor Documentation

§ ~CachedFreeList()

template<typename FreeList , size_t CacheSize = 16, unsigned Padding = cds::c_nCacheLineSize>
cds::intrusive::CachedFreeList< FreeList, CacheSize, Padding >::~CachedFreeList ( )

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

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 FreeList , size_t CacheSize = 16, unsigned Padding = cds::c_nCacheLineSize>
template<typename Disposer >
void cds::intrusive::CachedFreeList< FreeList, CacheSize, Padding >::clear ( Disposer  disp)

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.2.0 Developed by Maxim Khizhinsky aka khizmax 2007 - 2017
Autogenerated Wed Jan 4 2017 08:49:49 by Doxygen 1.8.12