Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:44:51

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