1 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) 6 7 #ifndef BOOST_FIBERS_DETAIL_SHARED_STATE_OBJECT_H 8 #define BOOST_FIBERS_DETAIL_SHARED_STATE_OBJECT_H 9 10 #include <memory> 11 12 #include <boost/config.hpp> 13 14 #include <boost/fiber/detail/config.hpp> 15 #include <boost/fiber/future/detail/shared_state.hpp> 16 17 #ifdef BOOST_HAS_ABI_HEADERS 18 # include BOOST_ABI_PREFIX 19 #endif 20 21 namespace boost { 22 namespace fibers { 23 namespace detail { 24 25 template< typename R, typename Allocator > 26 class shared_state_object : public shared_state< R > { 27 public: 28 typedef typename std::allocator_traits< Allocator >::template rebind_alloc< 29 shared_state_object 30 > allocator_type; 31 shared_state_object(allocator_type const & alloc)32 shared_state_object( allocator_type const& alloc) : 33 shared_state< R >{}, 34 alloc_{ alloc } { 35 } 36 37 protected: deallocate_future()38 void deallocate_future() noexcept override final { 39 destroy_( alloc_, this); 40 } 41 42 private: 43 allocator_type alloc_; 44 destroy_(allocator_type const & alloc,shared_state_object * p)45 static void destroy_( allocator_type const& alloc, shared_state_object * p) noexcept { 46 allocator_type a{ alloc }; 47 typedef std::allocator_traits< allocator_type > traity_type; 48 traity_type::destroy( a, p); 49 traity_type::deallocate( a, p, 1); 50 } 51 }; 52 53 }}} 54 55 #ifdef BOOST_HAS_ABI_HEADERS 56 # include BOOST_ABI_SUFFIX 57 #endif 58 59 #endif // BOOST_FIBERS_DETAIL_SHARED_STATE_OBJECT_H 60