#ifndef BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED #define BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED // Copyright 2018-2025 Emil Dotchevski and Reverge Studios, Inc. // 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) // This header implements the TLS API specified in tls.hpp using the C++11 // built-in thread_local storage class specifier. On Windows, this // implementation does not allow error objects to cross DLL boundaries. If this // is required, define BOOST_LEAF_CFG_WIN32=2 before including any LEAF headers // to enable the alternative implementation defined in tls_win32.hpp. #include #include namespace boost { namespace leaf { namespace detail { using atomic_unsigned_int = std::atomic; template struct BOOST_LEAF_SYMBOL_VISIBLE id_factory { static atomic_unsigned_int counter; }; template atomic_unsigned_int id_factory::counter(1); template struct BOOST_LEAF_SYMBOL_VISIBLE ptr { static thread_local T * p; }; template thread_local T * ptr::p; template struct BOOST_LEAF_SYMBOL_VISIBLE current_error_id_storage { static thread_local unsigned x; }; template thread_local unsigned current_error_id_storage::x; } // namespace detail } } // namespace boost::leaf //////////////////////////////////////// namespace boost { namespace leaf { namespace tls { BOOST_LEAF_ALWAYS_INLINE unsigned generate_next_error_id() noexcept { unsigned id = (detail::id_factory<>::counter += 4); BOOST_LEAF_ASSERT((id&3) == 1); return id; } BOOST_LEAF_ALWAYS_INLINE void write_current_error_id( unsigned x ) noexcept { detail::current_error_id_storage<>::x = x; } BOOST_LEAF_ALWAYS_INLINE unsigned read_current_error_id() noexcept { return detail::current_error_id_storage<>::x; } template BOOST_LEAF_ALWAYS_INLINE void reserve_ptr() { } template BOOST_LEAF_ALWAYS_INLINE void write_ptr( T * p ) noexcept { detail::ptr::p = p; } template BOOST_LEAF_ALWAYS_INLINE T * read_ptr() noexcept { return detail::ptr::p; } } // namespace tls } } // namespace boost::leaf #endif // #ifndef BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED