#ifndef BOOST_LEAF_CONFIG_TLS_GLOBALS_HPP_INCLUDED #define BOOST_LEAF_CONFIG_TLS_GLOBALS_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 globals, which // is suitable for single thread environments. #include namespace boost { namespace leaf { namespace detail { using atomic_unsigned_int = unsigned int; 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 T * p; }; template T * ptr::p; template struct BOOST_LEAF_SYMBOL_VISIBLE current_error_id_storage { static unsigned x; }; template unsigned current_error_id_storage::x = 0; } // 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 v ) noexcept { detail::current_error_id_storage<>::x = v; } 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_GLOBALS_HPP_INCLUDED