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_GLOBALS_HPP_INCLUDED
0002 #define BOOST_LEAF_CONFIG_TLS_GLOBALS_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 globals, which is suitable for single thread environments.
0013 
0014 #include <cstdint>
0015 
0016 namespace boost { namespace leaf {
0017 
0018 namespace leaf_detail
0019 {
0020     using atomic_unsigned_int = unsigned int;
0021 }
0022 
0023 namespace tls
0024 {
0025     template <class T>
0026     struct BOOST_LEAF_SYMBOL_VISIBLE ptr
0027     {
0028         static T * p;
0029     };
0030 
0031     template <class T>
0032     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 unsigned x;
0052     };
0053 
0054     template <class Tag>
0055     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     template <class Tag>
0070     void uint_increment() noexcept
0071     {
0072         ++tagged_uint<Tag>::x;
0073     }
0074 
0075     template <class Tag>
0076     void uint_decrement() noexcept
0077     {
0078         --tagged_uint<Tag>::x;
0079     }
0080 }
0081 
0082 } }
0083 
0084 #endif