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/continuation_ucontext.hpp" 9 #elif defined(BOOST_USE_WINFIB) 10 #include "boost/context/continuation_winfib.hpp" 11 #else 12 #include "boost/context/execution_context.hpp" 13 #endif 14 15 #include <boost/config.hpp> 16 17 #ifdef BOOST_HAS_ABI_HEADERS 18 # include BOOST_ABI_PREFIX 19 #endif 20 21 namespace boost { 22 namespace context { 23 namespace detail { 24 25 // zero-initialization 26 thread_local activation_record * current_rec; 27 thread_local static std::size_t counter; 28 29 // schwarz counter activation_record_initializer()30activation_record_initializer::activation_record_initializer() noexcept { 31 if ( 0 == counter++) { 32 current_rec = new activation_record(); 33 } 34 } 35 ~activation_record_initializer()36activation_record_initializer::~activation_record_initializer() { 37 if ( 0 == --counter) { 38 BOOST_ASSERT( current_rec->is_main_context() ); 39 delete current_rec; 40 } 41 } 42 43 } 44 45 namespace detail { 46 47 activation_record *& current()48activation_record::current() noexcept { 49 // initialized the first time control passes; per thread 50 thread_local static activation_record_initializer initializer; 51 return current_rec; 52 } 53 54 } 55 56 }} 57 58 #ifdef BOOST_HAS_ABI_HEADERS 59 # include BOOST_ABI_SUFFIX 60 #endif 61