2 // Copyright Oliver Kowalke 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // based on tss.hpp from boost.thread
9 #ifndef BOOST_FIBERS_DETAIL_FSS_H
10 #define BOOST_FIBERS_DETAIL_FSS_H
15 #include <boost/config.hpp>
16 #include <boost/intrusive_ptr.hpp>
18 #ifdef BOOST_HAS_ABI_HEADERS
19 # include BOOST_ABI_PREFIX
26 class fss_cleanup_function {
28 std::atomic< std::size_t > use_count_{ 0 };
31 typedef intrusive_ptr< fss_cleanup_function > ptr_t;
33 fss_cleanup_function() noexcept = default;
35 virtual ~fss_cleanup_function() = default;
37 virtual void operator()( void * data) = 0;
40 void intrusive_ptr_add_ref( fss_cleanup_function * p) noexcept {
41 p->use_count_.fetch_add( 1, std::memory_order_relaxed);
45 void intrusive_ptr_release( fss_cleanup_function * p) noexcept {
46 if ( 1 == p->use_count_.fetch_sub( 1, std::memory_order_release) ) {
47 std::atomic_thread_fence( std::memory_order_acquire);
55 #ifdef BOOST_HAS_ABI_HEADERS
56 # include BOOST_ABI_SUFFIX
59 #endif // BOOST_FIBERS_DETAIL_FSS_H