| 1 | // atomic_tools.hpp ------------------------------------------------------------------// |
| 2 | |
| 3 | // Copyright 2021 Andrey Semashev |
| 4 | |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // See http://www.boost.org/LICENSE_1_0.txt |
| 7 | |
| 8 | // See library home page at http://www.boost.org/libs/filesystem |
| 9 | |
| 10 | //--------------------------------------------------------------------------------------// |
| 11 | |
| 12 | #ifndef BOOST_FILESYSTEM_SRC_ATOMIC_TOOLS_HPP_ |
| 13 | #define BOOST_FILESYSTEM_SRC_ATOMIC_TOOLS_HPP_ |
| 14 | |
| 15 | #include <boost/filesystem/config.hpp> |
| 16 | |
| 17 | #if !defined(BOOST_FILESYSTEM_SINGLE_THREADED) |
| 18 | |
| 19 | #include "atomic_ref.hpp" |
| 20 | |
| 21 | namespace boost { |
| 22 | namespace filesystem { |
| 23 | namespace detail { |
| 24 | |
| 25 | //! Atomically loads the value |
| 26 | template< typename T > |
| 27 | BOOST_FORCEINLINE T atomic_load_relaxed(T& a) |
| 28 | { |
| 29 | return atomic_ns::atomic_ref< T >(a).load(atomic_ns::memory_order_relaxed); |
| 30 | } |
| 31 | |
| 32 | //! Atomically stores the value |
| 33 | template< typename T > |
| 34 | BOOST_FORCEINLINE void atomic_store_relaxed(T& a, T val) |
| 35 | { |
| 36 | atomic_ns::atomic_ref< T >(a).store(val, atomic_ns::memory_order_relaxed); |
| 37 | } |
| 38 | |
| 39 | } // namespace detail |
| 40 | } // namespace filesystem |
| 41 | } // namespace boost |
| 42 | |
| 43 | #else // !defined(BOOST_FILESYSTEM_SINGLE_THREADED) |
| 44 | |
| 45 | namespace boost { |
| 46 | namespace filesystem { |
| 47 | namespace detail { |
| 48 | |
| 49 | //! Atomically loads the value |
| 50 | template< typename T > |
| 51 | BOOST_FORCEINLINE T atomic_load_relaxed(T const& a) |
| 52 | { |
| 53 | return a; |
| 54 | } |
| 55 | |
| 56 | //! Atomically stores the value |
| 57 | template< typename T > |
| 58 | BOOST_FORCEINLINE void atomic_store_relaxed(T& a, T val) |
| 59 | { |
| 60 | a = val; |
| 61 | } |
| 62 | |
| 63 | } // namespace detail |
| 64 | } // namespace filesystem |
| 65 | } // namespace boost |
| 66 | |
| 67 | #endif // !defined(BOOST_FILESYSTEM_SINGLE_THREADED) |
| 68 | |
| 69 | #endif // BOOST_FILESYSTEM_SRC_ATOMIC_TOOLS_HPP_ |
| 70 | |