1 
2 //          Copyright Oliver Kowalke 2009.
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 #include "boost/coroutine/detail/coroutine_context.hpp"
8 
9 #ifdef BOOST_HAS_ABI_HEADERS
10 #  include BOOST_ABI_PREFIX
11 #endif
12 
13 #if defined(_MSC_VER)
14 # pragma warning(push)
15 # pragma warning(disable:4355)
16 #endif
17 
18 #if defined(BOOST_USE_SEGMENTED_STACKS)
19 extern "C" {
20 
21 void __splitstack_getcontext( void * [BOOST_COROUTINES_SEGMENTS]);
22 
23 void __splitstack_setcontext( void * [BOOST_COROUTINES_SEGMENTS]);
24 
25 }
26 #endif
27 
28 namespace boost {
29 namespace coroutines {
30 namespace detail {
31 
coroutine_context()32 coroutine_context::coroutine_context() :
33     palloc_(),
34     ctx_( 0)
35 {}
36 
coroutine_context(ctx_fn fn,preallocated const & palloc)37 coroutine_context::coroutine_context( ctx_fn fn, preallocated const& palloc) :
38     palloc_( palloc),
39     ctx_( context::make_fcontext( palloc_.sp, palloc_.size, fn) )
40 {}
41 
coroutine_context(coroutine_context const & other)42 coroutine_context::coroutine_context( coroutine_context const& other) :
43     palloc_( other.palloc_),
44     ctx_( other.ctx_)
45 {}
46 
47 coroutine_context &
operator =(coroutine_context const & other)48 coroutine_context::operator=( coroutine_context const& other)
49 {
50     if ( this == & other) return * this;
51 
52     palloc_ = other.palloc_;
53     ctx_ = other.ctx_;
54 
55     return * this;
56 }
57 
58 intptr_t
jump(coroutine_context & other,intptr_t param,bool preserve_fpu)59 coroutine_context::jump( coroutine_context & other, intptr_t param, bool preserve_fpu)
60 {
61 #if defined(BOOST_USE_SEGMENTED_STACKS)
62     __splitstack_getcontext( palloc_.sctx.segments_ctx);
63     __splitstack_setcontext( other.palloc_.sctx.segments_ctx);
64 
65     intptr_t ret = context::jump_fcontext( & ctx_, other.ctx_, param, preserve_fpu);
66 
67     __splitstack_setcontext( palloc_.sctx.segments_ctx);
68 
69     return ret;
70 #else
71     return context::jump_fcontext( & ctx_, other.ctx_, param, preserve_fpu);
72 #endif
73 }
74 
75 }}}
76 
77 #if defined(_MSC_VER)
78 # pragma warning(pop)
79 #endif
80 
81 #ifdef BOOST_HAS_ABI_HEADERS
82 #  include BOOST_ABI_SUFFIX
83 #endif
84