]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_t; | |
31 | ||
32 | shared_state_object( allocator_t const& alloc) : | |
33 | shared_state< R >(), alloc_( alloc) { | |
34 | } | |
35 | ||
36 | protected: | |
37 | void deallocate_future() noexcept override final { | |
38 | destroy_( alloc_, this); | |
39 | } | |
40 | ||
41 | private: | |
42 | allocator_t alloc_; | |
43 | ||
44 | static void destroy_( allocator_t const& alloc, shared_state_object * p) noexcept { | |
45 | allocator_t a{ alloc }; | |
46 | a.destroy( p); | |
47 | a.deallocate( p, 1); | |
48 | } | |
49 | }; | |
50 | ||
51 | }}} | |
52 | ||
53 | #ifdef BOOST_HAS_ABI_HEADERS | |
54 | # include BOOST_ABI_SUFFIX | |
55 | #endif | |
56 | ||
57 | #endif // BOOST_FIBERS_DETAIL_SHARED_STATE_OBJECT_H |