Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ target_include_directories(boost_lockfree INTERFACE include)

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.23 AND BOOST_LOCKFREE_USE_FILE_SET)
set(Headers
include/boost/lockfree/mpsc_queue.hpp
include/boost/lockfree/spsc_queue.hpp
include/boost/lockfree/spsc_value.hpp
include/boost/lockfree/policies.hpp
Expand Down
13 changes: 9 additions & 4 deletions doc/lockfree.qbk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[library Boost.Lockfree
[quickbook 1.4]
[authors [Blechmann, Tim]]
[copyright 2008-2011 Tim Blechmann]
[copyright 2008-2026 Tim Blechmann]
[category algorithms]
[purpose
lockfree concurrent data structures
Expand Down Expand Up @@ -115,15 +115,19 @@ lock-freedom:

[h2 Data Structures]

_lockfree_ implements four lock-free data structures:
_lockfree_ implements five lock-free data structures:

[variablelist
[[[classref boost::lockfree::queue]]
[a lock-free multi-producer/multi-consumer queue]
[a lock-free multi-producer/multi-consumer queue (Based on Michael & Scott's algorithm)]
]

[[[classref boost::lockfree::mpsc_queue]]
[a multi-producer/single-consumer queue (Based on Dmitry Vyukov's algorithm)]
]

[[[classref boost::lockfree::stack]]
[a lock-free multi-producer/multi-consumer stack]
[a lock-free multi-producer/multi-consumer stack (Based on Treiber's algorithm)]
]

[[[classref boost::lockfree::spsc_queue]]
Expand Down Expand Up @@ -278,6 +282,7 @@ _lockfree_ requires a c++14 compliant compiler. Users of MSVC are strongly recom
# [@http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.37.3574 Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms by Michael Scott and Maged Michael],
In Symposium on Principles of Distributed Computing, pages 267–275, 1996.
# [@http://books.google.com/books?id=pFSwuqtJgxYC M. Herlihy & Nir Shavit. The Art of Multiprocessor Programming], Morgan Kaufmann Publishers, 2008
# [@http://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-mpsc-node-based-queue Multiple Producer Single Consumer Lock-Free Queue by Dmitry Vyukov], 2010

[endsect]

Expand Down
83 changes: 83 additions & 0 deletions include/boost/lockfree/detail/freelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ class fixed_size_freelist : NodeStorage
deallocate< ThreadSafe >( index );
}

template < bool ThreadSafe >
void destruct( index_t index )
{
T* n = NodeStorage::nodes() + index;
n->~T();
deallocate< ThreadSafe >( index );
}

template < bool ThreadSafe >
void destruct( T* n )
{
Expand Down Expand Up @@ -673,6 +681,81 @@ using select_freelist_t = typename select_freelist< T, Alloc, IsCompileTimeSized

//----------------------------------------------------------------------------------------------------------------------

template < typename T, typename Alloc = std::allocator< T > >
class alignas( cacheline_bytes ) direct_allocator : Alloc
{
public:
typedef T* index_t;
typedef T* tagged_node_handle;

template < typename Allocator >
direct_allocator( Allocator const& alloc, std::size_t = 0 ) :
Alloc( alloc )
{}

template < bool ThreadSafe >
void reserve( std::size_t )
{}

template < bool ThreadSafe, bool Bounded >
T* construct( void )
{
T* node = Alloc::allocate( 1 );
if ( node )
new ( node ) T();
return node;
}

template < bool ThreadSafe, bool Bounded, typename ArgumentType >
T* construct( ArgumentType&& arg )
{
T* node = Alloc::allocate( 1 );
if ( node )
new ( node ) T( std::forward< ArgumentType >( arg ) );
return node;
}

template < bool ThreadSafe, bool Bounded, typename ArgumentType1, typename ArgumentType2 >
T* construct( ArgumentType1&& arg1, ArgumentType2&& arg2 )
{
T* node = Alloc::allocate( 1 );
if ( node )
new ( node ) T( std::forward< ArgumentType1 >( arg1 ), std::forward< ArgumentType2 >( arg2 ) );
return node;
}

template < bool ThreadSafe >
void destruct( tagged_node_handle node )
{
if ( node ) {
node->~T();
Alloc::deallocate( node, 1 );
}
}

bool is_lock_free( void ) const
{
return false;
}

T* get_handle( T* pointer ) const
{
return pointer;
}

T* get_pointer( T* tptr ) const
{
return tptr;
}

T* null_handle( void ) const
{
return nullptr;
}
};

//----------------------------------------------------------------------------------------------------------------------

template < typename T, bool IsNodeBased >
struct select_tagged_handle
{
Expand Down
3 changes: 3 additions & 0 deletions include/boost/lockfree/detail/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ template < typename bound_args, bool default_ = false >
using extract_allow_multiple_reads
= extract_integral_arg_or_default_t< bound_args, tag::allow_multiple_reads, bool, default_ >;

template < typename bound_args, bool default_ = false >
using extract_freelist = extract_integral_arg_or_default_t< bound_args, tag::freelist, bool, default_ >;

//----------------------------------------------------------------------------------------------------------------------

}}} // namespace boost::lockfree::detail
Expand Down
Loading
Loading