shared_state_object.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright Oliver Kowalke 2013.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_FIBERS_DETAIL_SHARED_STATE_OBJECT_H
  6. #define BOOST_FIBERS_DETAIL_SHARED_STATE_OBJECT_H
  7. #include <memory>
  8. #include <boost/config.hpp>
  9. #include <boost/fiber/detail/config.hpp>
  10. #include <boost/fiber/future/detail/shared_state.hpp>
  11. #ifdef BOOST_HAS_ABI_HEADERS
  12. # include BOOST_ABI_PREFIX
  13. #endif
  14. namespace boost {
  15. namespace fibers {
  16. namespace detail {
  17. template< typename R, typename Allocator >
  18. class shared_state_object : public shared_state< R > {
  19. public:
  20. typedef typename std::allocator_traits< Allocator >::template rebind_alloc<
  21. shared_state_object
  22. > allocator_type;
  23. shared_state_object( allocator_type const& alloc) :
  24. shared_state< R >{},
  25. alloc_{ alloc } {
  26. }
  27. protected:
  28. void deallocate_future() noexcept override final {
  29. destroy_( alloc_, this);
  30. }
  31. private:
  32. allocator_type alloc_;
  33. static void destroy_( allocator_type const& alloc, shared_state_object * p) noexcept {
  34. allocator_type a{ alloc };
  35. typedef std::allocator_traits< allocator_type > traity_type;
  36. traity_type::destroy( a, p);
  37. traity_type::deallocate( a, p, 1);
  38. }
  39. };
  40. }}}
  41. #ifdef BOOST_HAS_ABI_HEADERS
  42. # include BOOST_ABI_SUFFIX
  43. #endif
  44. #endif // BOOST_FIBERS_DETAIL_SHARED_STATE_OBJECT_H