blob: fc593ecb03ccf213ba35adbc54a0442428817a7d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright Oliver Kowalke 2009.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "boost/context/detail/config.hpp"
#if ! defined(BOOST_CONTEXT_NO_CXX11)
#include "boost/context/execution_context.hpp"
#include <boost/config.hpp>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost {
namespace context {
#if !defined(BOOST_NO_CXX11_THREAD_LOCAL)
namespace detail {
ecv1_activation_record::ptr_t &
ecv1_activation_record::current() noexcept {
thread_local static ptr_t current;
return current;
}
// zero-initialization
thread_local static std::size_t counter;
// schwarz counter
ecv1_activation_record_initializer::ecv1_activation_record_initializer() noexcept {
if ( 0 == counter++) {
ecv1_activation_record::current().reset( new ecv1_activation_record() );
}
}
ecv1_activation_record_initializer::~ecv1_activation_record_initializer() {
if ( 0 == --counter) {
BOOST_ASSERT( ecv1_activation_record::current()->is_main_context() );
delete ecv1_activation_record::current().detach();
}
}
}
namespace v1 {
execution_context
execution_context::current() noexcept {
// initialized the first time control passes; per thread
thread_local static detail::ecv1_activation_record_initializer initializer;
return execution_context();
}
}
#endif
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif
|