1 //
2 // detail/gcc_sync_fenced_block.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2016 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 ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP
12 #define 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 "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 "asio/detail/push_options.hpp"
26 
27 namespace asio {
28 namespace detail {
29 
30 class gcc_sync_fenced_block
31   : private noncopyable
32 {
33 public:
34   enum half_or_full_t { half, full };
35 
36   // Constructor.
gcc_sync_fenced_block(half_or_full_t)37   explicit gcc_sync_fenced_block(half_or_full_t)
38     : value_(0)
39   {
40     __sync_lock_test_and_set(&value_, 1);
41   }
42 
43   // Destructor.
~gcc_sync_fenced_block()44   ~gcc_sync_fenced_block()
45   {
46     __sync_lock_release(&value_);
47   }
48 
49 private:
50   int value_;
51 };
52 
53 } // namespace detail
54 } // namespace asio
55 
56 #include "asio/detail/pop_options.hpp"
57 
58 #endif // defined(__GNUC__)
59        // && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4))
60        // && !defined(__INTEL_COMPILER) && !defined(__ICL)
61        // && !defined(__ICC) && !defined(__ECC) && !defined(__PATHSCALE__)
62 
63 #endif // ASIO_DETAIL_GCC_SYNC_FENCED_BLOCK_HPP
64