Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:34:54

0001 #ifndef BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED
0002 #define BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED
0003 
0004 // Copyright 2018-2024 Emil Dotchevski and Reverge Studios, Inc.
0005 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 // LEAF requires thread local storage support for pointers and for uin32_t values.
0009 
0010 // This header implements thread local storage for pointers and for unsigned int
0011 // values using the C++11 built-in thread_local storage class specifier.
0012 
0013 #include <cstdint>
0014 #include <atomic>
0015 
0016 namespace boost { namespace leaf {
0017 
0018 namespace detail
0019 {
0020     using atomic_unsigned_int = std::atomic<unsigned int>;
0021 }
0022 
0023 namespace tls
0024 {
0025     template <class T>
0026     struct BOOST_LEAF_SYMBOL_VISIBLE ptr
0027     {
0028         static thread_local T * p;
0029     };
0030 
0031     template <class T>
0032     thread_local T * ptr<T>::p;
0033 
0034     template <class T>
0035     T * read_ptr() noexcept
0036     {
0037         return ptr<T>::p;
0038     }
0039 
0040     template <class T>
0041     void write_ptr( T * p ) noexcept
0042     {
0043         ptr<T>::p = p;
0044     }
0045 
0046     ////////////////////////////////////////
0047 
0048     template <class Tag>
0049     struct BOOST_LEAF_SYMBOL_VISIBLE tagged_uint
0050     {
0051         static thread_local unsigned x;
0052     };
0053 
0054     template <class Tag>
0055     thread_local unsigned tagged_uint<Tag>::x;
0056 
0057     template <class Tag>
0058     unsigned read_uint() noexcept
0059     {
0060         return tagged_uint<Tag>::x;
0061     }
0062 
0063     template <class Tag>
0064     void write_uint( unsigned x ) noexcept
0065     {
0066         tagged_uint<Tag>::x = x;
0067     }
0068 }
0069 
0070 } }
0071 
0072 #endif // BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED