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