|
||||
File indexing completed on 2025-01-30 09:33:57
0001 /* 0002 * Distributed under the Boost Software License, Version 1.0. 0003 * (See accompanying file LICENSE_1_0.txt or copy at 0004 * http://www.boost.org/LICENSE_1_0.txt) 0005 * 0006 * Copyright (c) 2020 Andrey Semashev 0007 */ 0008 /*! 0009 * \file atomic/detail/gcc_atomic_memory_order_utils.hpp 0010 * 0011 * This header contains utilities for working with gcc atomic memory order constants. 0012 */ 0013 0014 #ifndef BOOST_ATOMIC_DETAIL_GCC_ATOMIC_MEMORY_ORDER_UTILS_HPP_INCLUDED_ 0015 #define BOOST_ATOMIC_DETAIL_GCC_ATOMIC_MEMORY_ORDER_UTILS_HPP_INCLUDED_ 0016 0017 #include <boost/memory_order.hpp> 0018 #include <boost/atomic/detail/config.hpp> 0019 #include <boost/atomic/detail/header.hpp> 0020 0021 #ifdef BOOST_HAS_PRAGMA_ONCE 0022 #pragma once 0023 #endif 0024 0025 namespace boost { 0026 namespace atomics { 0027 namespace detail { 0028 0029 /*! 0030 * The function converts \c boost::memory_order values to the compiler-specific constants. 0031 * 0032 * NOTE: The intention is that the function is optimized away by the compiler, and the 0033 * compiler-specific constants are passed to the intrinsics. Unfortunately, constexpr doesn't 0034 * work in this case because the standard atomics interface require memory ordering 0035 * constants to be passed as function arguments, at which point they stop being constexpr. 0036 * However, it is crucial that the compiler sees constants and not runtime values, 0037 * because otherwise it just ignores the ordering value and always uses seq_cst. 0038 * This is the case with Intel C++ Compiler 14.0.3 (Composer XE 2013 SP1, update 3) and 0039 * gcc 4.8.2. Intel Compiler issues a warning in this case: 0040 * 0041 * warning #32013: Invalid memory order specified. Defaulting to seq_cst memory order. 0042 * 0043 * while gcc acts silently. 0044 * 0045 * To mitigate the problem ALL functions, including the atomic<> members must be 0046 * declared with BOOST_FORCEINLINE. In this case the compilers are able to see that 0047 * all functions are called with constant orderings and call intrinstcts properly. 0048 * 0049 * Unfortunately, this still doesn't work in debug mode as the compiler doesn't 0050 * propagate constants even when functions are marked with BOOST_FORCEINLINE. In this case 0051 * all atomic operaions will be executed with seq_cst semantics. 0052 */ 0053 BOOST_FORCEINLINE BOOST_CONSTEXPR int convert_memory_order_to_gcc(memory_order order) BOOST_NOEXCEPT 0054 { 0055 return (order == memory_order_relaxed ? __ATOMIC_RELAXED : (order == memory_order_consume ? __ATOMIC_CONSUME : 0056 (order == memory_order_acquire ? __ATOMIC_ACQUIRE : (order == memory_order_release ? __ATOMIC_RELEASE : 0057 (order == memory_order_acq_rel ? __ATOMIC_ACQ_REL : __ATOMIC_SEQ_CST))))); 0058 } 0059 0060 } // namespace detail 0061 } // namespace atomics 0062 } // namespace boost 0063 0064 #include <boost/atomic/detail/footer.hpp> 0065 0066 #endif // BOOST_ATOMIC_DETAIL_GCC_ATOMIC_MEMORY_ORDER_UTILS_HPP_INCLUDED_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |