]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // Copyright Oliver Kowalke 2014. | |
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_FIBER_DETAIL_WRAP_H | |
8 | #define BOOST_FIBER_DETAIL_WRAP_H | |
9 | ||
10 | #include <type_traits> | |
11 | ||
12 | #include <boost/config.hpp> | |
13 | #include <boost/context/detail/invoke.hpp> | |
14 | #include <boost/context/execution_context.hpp> | |
15 | ||
16 | #include <boost/fiber/detail/config.hpp> | |
17 | #include <boost/fiber/detail/data.hpp> | |
18 | ||
19 | #ifdef BOOST_HAS_ABI_HEADERS | |
20 | # include BOOST_ABI_PREFIX | |
21 | #endif | |
22 | ||
23 | namespace boost { | |
24 | namespace fibers { | |
25 | namespace detail { | |
26 | ||
27 | #if (BOOST_EXECUTION_CONTEXT==1) | |
28 | template< typename Fn1, typename Fn2, typename Tpl > | |
29 | class wrapper { | |
30 | private: | |
31 | typename std::decay< Fn1 >::type fn1_; | |
32 | typename std::decay< Fn2 >::type fn2_; | |
33 | typename std::decay< Tpl >::type tpl_; | |
34 | boost::context::execution_context ctx_; | |
35 | ||
36 | public: | |
37 | wrapper( Fn1 && fn1, Fn2 && fn2, Tpl && tpl, | |
38 | boost::context::execution_context const& ctx) : | |
39 | fn1_( std::move( fn1) ), | |
40 | fn2_( std::move( fn2) ), | |
41 | tpl_( std::move( tpl) ), | |
42 | ctx_{ ctx } { | |
43 | } | |
44 | ||
45 | wrapper( wrapper const&) = delete; | |
46 | wrapper & operator=( wrapper const&) = delete; | |
47 | ||
48 | wrapper( wrapper && other) = default; | |
49 | wrapper & operator=( wrapper && other) = default; | |
50 | ||
51 | void operator()( void * vp) { | |
52 | boost::context::detail::invoke( | |
53 | std::move( fn1_), | |
54 | fn2_, tpl_, ctx_, vp); | |
55 | } | |
56 | }; | |
57 | ||
58 | template< typename Fn1, typename Fn2, typename Tpl > | |
59 | wrapper< Fn1, Fn2, Tpl > | |
60 | wrap( Fn1 && fn1, Fn2 && fn2, Tpl && tpl, | |
61 | boost::context::execution_context const& ctx) { | |
62 | return wrapper< Fn1, Fn2, Tpl >( | |
63 | std::forward< Fn1 >( fn1), | |
64 | std::forward< Fn2 >( fn2), | |
65 | std::forward< Tpl >( tpl), | |
66 | ctx); | |
67 | } | |
68 | #else | |
69 | template< typename Fn1, typename Fn2, typename Tpl > | |
70 | class wrapper { | |
71 | private: | |
72 | typename std::decay< Fn1 >::type fn1_; | |
73 | typename std::decay< Fn2 >::type fn2_; | |
74 | typename std::decay< Tpl >::type tpl_; | |
75 | ||
76 | public: | |
77 | wrapper( Fn1 && fn1, Fn2 && fn2, Tpl && tpl) : | |
78 | fn1_( std::move( fn1) ), | |
79 | fn2_( std::move( fn2) ), | |
80 | tpl_( std::move( tpl) ) { | |
81 | } | |
82 | ||
83 | wrapper( wrapper const&) = delete; | |
84 | wrapper & operator=( wrapper const&) = delete; | |
85 | ||
86 | wrapper( wrapper && other) = default; | |
87 | wrapper & operator=( wrapper && other) = default; | |
88 | ||
89 | boost::context::execution_context< data_t * > | |
90 | operator()( boost::context::execution_context< data_t * > ctx, data_t * dp) { | |
91 | return boost::context::detail::invoke( | |
92 | std::move( fn1_), | |
93 | fn2_, tpl_, std::move( ctx), dp); | |
94 | } | |
95 | }; | |
96 | ||
97 | template< typename Fn1, typename Fn2, typename Tpl > | |
98 | wrapper< Fn1, Fn2, Tpl > | |
99 | wrap( Fn1 && fn1, Fn2 && fn2, Tpl && tpl) { | |
100 | return wrapper< Fn1, Fn2, Tpl >( | |
101 | std::forward< Fn1 >( fn1), | |
102 | std::forward< Fn2 >( fn2), | |
103 | std::forward< Tpl >( tpl) ); | |
104 | } | |
105 | #endif | |
106 | ||
107 | }}} | |
108 | ||
109 | #ifdef BOOST_HAS_ABI_HEADERS | |
110 | #include BOOST_ABI_SUFFIX | |
111 | #endif | |
112 | ||
113 | #endif // BOOST_FIBER_DETAIL_WRAP_H |