]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #ifndef BOOST_LEAF_CONFIG_TLS_GLOBALS_HPP_INCLUDED |
2 | #define BOOST_LEAF_CONFIG_TLS_GLOBALS_HPP_INCLUDED | |
3 | ||
4 | // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc. | |
5 | ||
6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | // LEAF requires thread local storage support for pointers and for uin32_t values. | |
10 | ||
11 | // This header implements "thread local" storage for pointers and for uint32_t | |
12 | // values using globals, which is suitable for single thread environments. | |
13 | ||
14 | #include <cstdint> | |
15 | ||
16 | namespace boost { namespace leaf { | |
17 | ||
18 | namespace leaf_detail | |
19 | { | |
20 | using atomic_unsigned_int = unsigned int; | |
21 | } | |
22 | ||
23 | namespace tls | |
24 | { | |
25 | template <class T> | |
26 | struct BOOST_LEAF_SYMBOL_VISIBLE ptr | |
27 | { | |
28 | static T * p; | |
29 | }; | |
30 | ||
31 | template <class T> | |
32 | T * ptr<T>::p; | |
33 | ||
34 | template <class T> | |
35 | T * read_ptr() noexcept | |
36 | { | |
37 | return ptr<T>::p; | |
38 | } | |
39 | ||
40 | template <class T> | |
41 | void write_ptr( T * p ) noexcept | |
42 | { | |
43 | ptr<T>::p = p; | |
44 | } | |
45 | ||
46 | //////////////////////////////////////// | |
47 | ||
48 | template <class Tag> | |
49 | struct BOOST_LEAF_SYMBOL_VISIBLE tagged_uint32 | |
50 | { | |
51 | static std::uint32_t x; | |
52 | }; | |
53 | ||
54 | template <class Tag> | |
55 | std::uint32_t tagged_uint32<Tag>::x; | |
56 | ||
57 | template <class Tag> | |
58 | std::uint32_t read_uint32() noexcept | |
59 | { | |
60 | return tagged_uint32<Tag>::x; | |
61 | } | |
62 | ||
63 | template <class Tag> | |
64 | void write_uint32( std::uint32_t x ) noexcept | |
65 | { | |
66 | tagged_uint32<Tag>::x = x; | |
67 | } | |
68 | ||
69 | template <class Tag> | |
70 | void uint32_increment() noexcept | |
71 | { | |
72 | ++tagged_uint32<Tag>::x; | |
73 | } | |
74 | ||
75 | template <class Tag> | |
76 | void uint32_decrement() noexcept | |
77 | { | |
78 | --tagged_uint32<Tag>::x; | |
79 | } | |
80 | } | |
81 | ||
82 | } } | |
83 | ||
84 | #endif |