• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 //          Copyright Oliver Kowalke 2017.
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 #if defined(BOOST_USE_UCONTEXT)
8 #include "boost/context/fiber_ucontext.hpp"
9 #elif defined(BOOST_USE_WINFIB)
10 #include "boost/context/fiber_winfib.hpp"
11 #endif
12 
13 #include <boost/config.hpp>
14 
15 #ifdef BOOST_HAS_ABI_HEADERS
16 # include BOOST_ABI_PREFIX
17 #endif
18 
19 namespace boost {
20 namespace context {
21 namespace detail {
22 
23 // zero-initialization
24 thread_local fiber_activation_record * fib_current_rec;
25 thread_local static std::size_t counter;
26 
27 // schwarz counter
fiber_activation_record_initializer()28 fiber_activation_record_initializer::fiber_activation_record_initializer() noexcept {
29     if ( 0 == counter++) {
30         fib_current_rec = new fiber_activation_record();
31     }
32 }
33 
~fiber_activation_record_initializer()34 fiber_activation_record_initializer::~fiber_activation_record_initializer() {
35     if ( 0 == --counter) {
36         BOOST_ASSERT( fib_current_rec->is_main_context() );
37         delete fib_current_rec;
38     }
39 }
40 
41 }
42 
43 namespace detail {
44 
45 fiber_activation_record *&
current()46 fiber_activation_record::current() noexcept {
47     // initialized the first time control passes; per thread
48     thread_local static fiber_activation_record_initializer initializer;
49     return fib_current_rec;
50 }
51 
52 }
53 
54 }}
55 
56 #ifdef BOOST_HAS_ABI_HEADERS
57 # include BOOST_ABI_SUFFIX
58 #endif
59