1 // 2 // detail/gcc_sync_fenced_block.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 // 10 11 #ifndef BOOST_ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP 12 #define BOOST_ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/asio/detail/config.hpp> 19 20 #if defined(__GNUC__) \ 21 && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)) \ 22 && !defined(__INTEL_COMPILER) && !defined(__ICL) \ 23 && !defined(__ICC) && !defined(__ECC) && !defined(__PATHSCALE__) 24 25 #include <boost/asio/detail/noncopyable.hpp> 26 27 #include <boost/asio/detail/push_options.hpp> 28 29 namespace boost { 30 namespace asio { 31 namespace detail { 32 33 class gcc_sync_fenced_block 34 : private noncopyable 35 { 36 public: 37 enum half_or_full_t { half, full }; 38 39 // Constructor. gcc_sync_fenced_block(half_or_full_t)40 explicit gcc_sync_fenced_block(half_or_full_t) 41 : value_(0) 42 { 43 __sync_lock_test_and_set(&value_, 1); 44 } 45 46 // Destructor. ~gcc_sync_fenced_block()47 ~gcc_sync_fenced_block() 48 { 49 __sync_lock_release(&value_); 50 } 51 52 private: 53 int value_; 54 }; 55 56 } // namespace detail 57 } // namespace asio 58 } // namespace boost 59 60 #include <boost/asio/detail/pop_options.hpp> 61 62 #endif // defined(__GNUC__) 63 // && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)) 64 // && !defined(__INTEL_COMPILER) && !defined(__ICL) 65 // && !defined(__ICC) && !defined(__ECC) && !defined(__PATHSCALE__) 66 67 #endif // BOOST_ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP 68