Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/spsc value #94

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
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
50 changes: 29 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,118 +33,118 @@ jobs:
matrix:
include:
- toolset: gcc-5
cxxstd: "11,14,1z"
cxxstd: "14,1z"
os: ubuntu-22.04
container: ubuntu:16.04
install: g++-5
supported: true
- toolset: gcc-6
cxxstd: "11,14,1z"
cxxstd: "14,1z"
os: ubuntu-22.04
container: ubuntu:16.04
install: g++-6
supported: true
- toolset: gcc-7
cxxstd: "11,14,17"
cxxstd: "14,17"
os: ubuntu-22.04
container: ubuntu:18.04
install: g++-7
supported: true
- toolset: gcc-8
cxxstd: "11,14,17,2a"
cxxstd: "14,17,2a"
os: ubuntu-22.04
container: ubuntu:18.04
install: g++-8
supported: true
- toolset: gcc-9
cxxstd: "11,14,17,2a"
cxxstd: "14,17,2a"
os: ubuntu-22.04
container: ubuntu:18.04
install: g++-9
supported: true
- toolset: gcc-10
cxxstd: "11,14,17,2a"
cxxstd: "14,17,2a"
os: ubuntu-22.04
install: g++-10
supported: true
- toolset: gcc-11
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: ubuntu-22.04
install: g++-11
supported: true
- toolset: gcc-12
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: ubuntu-22.04
install: g++-12
supported: true
- toolset: gcc-13
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: ubuntu-22.04
install: g++-13
supported: true
- toolset: clang
install: clang-9
compiler: clang++-9
cxxstd: "11,14,17"
cxxstd: "14,17"
os: ubuntu-22.04
container: ubuntu:18.04
- toolset: clang
install: clang-10
compiler: clang++-10
cxxstd: "11,14,17,2a"
cxxstd: "14,17,2a"
os: ubuntu-20.04
supported: true
- toolset: clang
install: clang-11
compiler: clang++-11
cxxstd: "11,14,17,2a"
cxxstd: "14,17,2a"
os: ubuntu-20.04
supported: true
- toolset: clang
install: clang-12
compiler: clang++-12
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: ubuntu-22.04
supported: true
- toolset: clang
install: clang-13
compiler: clang++-13
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: ubuntu-22.04
supported: true
- toolset: clang
install: clang-14
compiler: clang++-14
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: ubuntu-22.04
supported: true
- toolset: clang
install: clang-15
compiler: clang++-15
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: ubuntu-22.04
supported: true
# - toolset: clang
# install: clang-16
# compiler: clang++-16
# cxxstd: "11,14,17,20"
# cxxstd: "14,17,20"
# os: ubuntu-22.04
# supported: true

# macos
- description: macos-11
toolset: clang
cxxstd: "11,14,17,2a"
cxxstd: "14,17,2a"
os: macos-11
supported: true
- description: macos-12
toolset: clang
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: macos-11
supported: true
- description: macos-13
toolset: clang
cxxstd: "11,14,17,20"
cxxstd: "14,17,20"
os: macos-11
supported: true

Expand Down Expand Up @@ -175,6 +175,14 @@ jobs:
sudo /usr/local/bin/pip install cmake
- uses: actions/checkout@v3

- name: Cache ccache
uses: actions/cache@v2
if: env.B2_USE_CCACHE
with:
path: ~/.ccache
key: ${{matrix.os}}-${{matrix.container}}-${{matrix.compiler}}-${{github.sha}}
restore-keys: ${{matrix.os}}-${{matrix.container}}-${{matrix.compiler}}-

- name: Install packages
if: matrix.install
run: |
Expand Down Expand Up @@ -275,7 +283,7 @@ jobs:
addrmd: 64
os: windows-2019
- toolset: gcc
cxxstd: "11,14,17,2a"
cxxstd: "14,17,2a"
addrmd: 64
cxxflags: "cxxflags=-Wa,-mbig-obj"
supported: true
Expand Down
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,50 @@ project(boost_lockfree VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

option(BOOST_LOCKFREE_BUILD_TESTS "Build boost::lockfree tests" ${BUILD_TESTING})

if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

add_library(boost_lockfree INTERFACE)
add_library(Boost::lockfree ALIAS boost_lockfree)

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.23)
set(Headers
include/boost/lockfree/spsc_queue.hpp
include/boost/lockfree/spsc_value.hpp
include/boost/lockfree/policies.hpp
include/boost/lockfree/queue.hpp
include/boost/lockfree/lockfree_forward.hpp
include/boost/lockfree/detail/prefix.hpp
include/boost/lockfree/detail/copy_payload.hpp
include/boost/lockfree/detail/tagged_ptr_dcas.hpp
include/boost/lockfree/detail/tagged_ptr.hpp
include/boost/lockfree/detail/tagged_ptr_ptrcompression.hpp
include/boost/lockfree/detail/atomic.hpp
include/boost/lockfree/detail/copy_payload.hpp
include/boost/lockfree/detail/freelist.hpp
include/boost/lockfree/detail/parameter.hpp
include/boost/lockfree/detail/prefix.hpp
include/boost/lockfree/detail/tagged_ptr.hpp
include/boost/lockfree/detail/tagged_ptr_dcas.hpp
include/boost/lockfree/detail/tagged_ptr_ptrcompression.hpp
include/boost/lockfree/detail/uses_optional.hpp
include/boost/lockfree/stack.hpp
)

target_sources(boost_lockfree PUBLIC FILE_SET HEADERS FILES ${Headers} )
endif()

target_compile_features(boost_lockfree INTERFACE cxx_std_14)
set_target_properties( boost_lockfree PROPERTIES CMAKE_CXX_STANDARD_REQUIRED 14)

target_include_directories(boost_lockfree INTERFACE include)

target_link_libraries(boost_lockfree
INTERFACE
Boost::align
Boost::array
Boost::assert
Boost::atomic
Boost::config
Boost::core
Boost::integer
Boost::iterator
Boost::mpl
Boost::parameter
Boost::predef
Boost::static_assert
Boost::tuple
Boost::type_traits
Boost::utility
)

Expand Down
10 changes: 9 additions & 1 deletion doc/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

using quickbook ;
using boostbook ;
using doxygen ;
using xsltproc ;

import set ;
import doxygen ;
import quickbook ;
import xsltproc ;
import notfile ;
import path ;

doxygen autodoc
:
Expand Down
38 changes: 13 additions & 25 deletions doc/lockfree.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ lock-freedom:

[h2 Data Structures]

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

[variablelist
[[[classref boost::lockfree::queue]]
Expand All @@ -129,6 +129,10 @@ _lockfree_ implements three lock-free data structures:
[[[classref boost::lockfree::spsc_queue]]
[a wait-free single-producer/single-consumer queue (commonly known as ringbuffer)]
]

[[[classref boost::lockfree::spsc_value]]
[a wait-free single-producer/single-consumer value (commonly known as triple buffer)]
]
]

[h3 Data Structure Configuration]
Expand All @@ -150,7 +154,11 @@ The data structures can be configured with [@boost:/libs/parameter/doc/html/inde
]

[[[classref boost::lockfree::allocator]]
[Defines the allocator. _lockfree_ supports stateful allocator and is compatible with [@boost:/libs/interprocess/index.html Boost.Interprocess] allocators.]
[Defines the allocator.]
]

[[[classref boost::lockfree::allow_multiple_reads]]
[Configures the [classref boost::lockfree::spsc_value] to allow the content to be read multiple times.]
]
]

Expand All @@ -161,7 +169,7 @@ The data structures can be configured with [@boost:/libs/parameter/doc/html/inde

[h2 Queue]

The [classref boost::lockfree::queue boost::lockfree::queue] class implements a multi-writer/multi-reader queue. The
The [classref boost::lockfree::queue] class implements a multi-writer/multi-reader queue. The
following example shows how integer values are produced and consumed by 4 threads each:

[import ../examples/queue.cpp]
Expand All @@ -177,7 +185,7 @@ consumed 40000000 objects.

[h2 Stack]

The [classref boost::lockfree::stack boost::lockfree::stack] class implements a multi-writer/multi-reader stack. The
The [classref boost::lockfree::stack] class implements a multi-writer/multi-reader stack. The
following example shows how integer values are produced and consumed by 4 threads each:

[import ../examples/stack.cpp]
Expand Down Expand Up @@ -212,16 +220,6 @@ consumed 10000000 objects.

[section Rationale]

[section Data Structures]

The implementations are implementations of well-known data structures. The queue is based on
[@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],
the stack is based on [@http://books.google.com/books?id=YQg3HAAACAAJ Systems programming: coping with parallelism by R. K. Treiber]
and the spsc_queue is considered as 'folklore' and is implemented in several open-source projects including the linux kernel. All
data structures are discussed in detail in [@http://books.google.com/books?id=pFSwuqtJgxYC "The Art of Multiprocessor Programming" by Herlihy & Shavit].

[endsect]

[section Memory Management]

The lock-free [classref boost::lockfree::queue] and [classref boost::lockfree::stack] classes are node-based data structures,
Expand Down Expand Up @@ -270,17 +268,7 @@ problem is the blocking emulation of lock-free atomics, which in the current imp

[section Supported Platforms & Compilers]

_lockfree_ has been tested on the following platforms:

* g++ 4.4, 4.5 and 4.6, linux, x86 & x86_64
* clang++ 3.0, linux, x86 & x86_64

[endsect]

[section Future Developments]

* More data structures (set, hash table, dequeue)
* Backoff schemes (exponential backoff or elimination)
_lockfree_ requires a c++14 compliant compiler

[endsect]

Expand Down
48 changes: 2 additions & 46 deletions include/boost/lockfree/detail/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,7 @@
#ifndef BOOST_LOCKFREE_DETAIL_ATOMIC_HPP
#define BOOST_LOCKFREE_DETAIL_ATOMIC_HPP

#include <boost/config.hpp>

#ifndef BOOST_LOCKFREE_FORCE_STD_ATOMIC

# define BOOST_LOCKFREE_NO_HDR_ATOMIC

// MSVC supports atomic<> from version 2012 onwards.
# if defined( BOOST_MSVC ) && ( BOOST_MSVC >= 1700 )
# undef BOOST_LOCKFREE_NO_HDR_ATOMIC
# endif


// GCC supports atomic<> from version 4.8 onwards.
# if ( BOOST_GCC >= 40800 ) && ( __cplusplus >= 201103L )
# undef BOOST_LOCKFREE_NO_HDR_ATOMIC
# endif


// Apple clang is 2 mayor versions ahead, but in fact 1 minor version behind
# ifdef BOOST_CLANG

# define BOOST_ATOMIC_CLANG_VERSION ( __clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__ )

# if defined( __apple_build_version__ ) && ( BOOST_ATOMIC_CLANG_VERSION >= 60100 ) && ( __cplusplus >= 201103L )
# undef BOOST_LOCKFREE_NO_HDR_ATOMIC
# endif

# if !defined( __apple_build_version__ ) && ( BOOST_ATOMIC_CLANG_VERSION >= 30600 ) && ( __cplusplus >= 201103L )
# undef BOOST_LOCKFREE_NO_HDR_ATOMIC
# endif

# undef BOOST_ATOMIC_CLANG_VERSION

# endif // BOOST_CLANG

// Stdlib should also be checked
# include <boost/config.hpp>
# if defined( BOOST_NO_CXX11_HDR_ATOMIC ) && !defined( BOOST_LOCKFREE_NO_HDR_ATOMIC )
# define BOOST_LOCKFREE_NO_HDR_ATOMIC
# endif

#endif // BOOST_LOCKFREE_FORCE_STD_ATOMIC


#if defined( BOOST_LOCKFREE_NO_HDR_ATOMIC ) || defined( BOOST_LOCKFREE_FORCE_BOOST_ATOMIC )
#if defined( BOOST_LOCKFREE_FORCE_BOOST_ATOMIC )
# include <boost/atomic.hpp>
#else
# include <atomic>
Expand All @@ -60,7 +16,7 @@
namespace boost { namespace lockfree {
namespace detail {

#if defined( BOOST_LOCKFREE_NO_HDR_ATOMIC ) || defined( BOOST_LOCKFREE_FORCE_BOOST_ATOMIC )
#if defined( BOOST_LOCKFREE_FORCE_BOOST_ATOMIC )
using boost::atomic;
using boost::memory_order_acquire;
using boost::memory_order_consume;
Expand Down
Loading
Loading