]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
11fdf7f2 TL |
7 | #include "boost/context/detail/config.hpp" |
8 | ||
9 | #if ! defined(BOOST_CONTEXT_NO_CXX11) | |
7c673cae | 10 | |
11fdf7f2 | 11 | #include "boost/context/execution_context.hpp" |
7c673cae FG |
12 | #include <boost/config.hpp> |
13 | ||
14 | #ifdef BOOST_HAS_ABI_HEADERS | |
15 | # include BOOST_ABI_PREFIX | |
16 | #endif | |
17 | ||
7c673cae FG |
18 | namespace boost { |
19 | namespace context { | |
11fdf7f2 TL |
20 | |
21 | #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) | |
22 | ||
7c673cae FG |
23 | namespace detail { |
24 | ||
11fdf7f2 TL |
25 | ecv1_activation_record::ptr_t & |
26 | ecv1_activation_record::current() noexcept { | |
27 | thread_local static ptr_t current; | |
28 | return current; | |
29 | } | |
7c673cae FG |
30 | |
31 | // zero-initialization | |
32 | thread_local static std::size_t counter; | |
33 | ||
34 | // schwarz counter | |
11fdf7f2 | 35 | ecv1_activation_record_initializer::ecv1_activation_record_initializer() noexcept { |
7c673cae | 36 | if ( 0 == counter++) { |
11fdf7f2 | 37 | ecv1_activation_record::current().reset( new ecv1_activation_record() ); |
7c673cae FG |
38 | } |
39 | } | |
40 | ||
11fdf7f2 | 41 | ecv1_activation_record_initializer::~ecv1_activation_record_initializer() { |
7c673cae | 42 | if ( 0 == --counter) { |
11fdf7f2 TL |
43 | BOOST_ASSERT( ecv1_activation_record::current()->is_main_context() ); |
44 | delete ecv1_activation_record::current().detach(); | |
7c673cae FG |
45 | } |
46 | } | |
47 | ||
48 | } | |
49 | ||
11fdf7f2 TL |
50 | namespace v1 { |
51 | ||
7c673cae FG |
52 | execution_context |
53 | execution_context::current() noexcept { | |
54 | // initialized the first time control passes; per thread | |
11fdf7f2 | 55 | thread_local static detail::ecv1_activation_record_initializer initializer; |
7c673cae FG |
56 | return execution_context(); |
57 | } | |
58 | ||
11fdf7f2 TL |
59 | } |
60 | ||
7c673cae FG |
61 | #endif |
62 | ||
11fdf7f2 TL |
63 | }} |
64 | ||
b32b8144 FG |
65 | #ifdef BOOST_HAS_ABI_HEADERS |
66 | # include BOOST_ABI_SUFFIX | |
67 | #endif | |
11fdf7f2 TL |
68 | |
69 | #endif |