]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/asio/detail/gcc_x86_fenced_block.hpp
Manually merged pull request #222
[casparcg] / dependencies / boost / boost / asio / detail / gcc_x86_fenced_block.hpp
1 //
2 // detail/gcc_x86_fenced_block.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2011 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_X86_FENCED_BLOCK_HPP
12 #define BOOST_ASIO_DETAIL_GCC_X86_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__) && (defined(__i386__) || defined(__x86_64__))
21
22 #include <boost/asio/detail/push_options.hpp>
23
24 namespace boost {
25 namespace asio {
26 namespace detail {
27
28 class gcc_x86_fenced_block
29   : private noncopyable
30 {
31 public:
32   enum half_t { half };
33   enum full_t { full };
34
35   // Constructor for a half fenced block.
36   explicit gcc_x86_fenced_block(half_t)
37   {
38   }
39
40   // Constructor for a full fenced block.
41   explicit gcc_x86_fenced_block(full_t)
42   {
43     barrier1();
44   }
45
46   // Destructor.
47   ~gcc_x86_fenced_block()
48   {
49     barrier2();
50   }
51
52 private:
53   static int barrier1()
54   {
55     int r = 0, m = 1;
56     __asm__ __volatile__ (
57         "xchgl %0, %1" :
58         "=r"(r), "=m"(m) :
59         "0"(1), "m"(m) :
60         "memory", "cc");
61     return r;
62   }
63
64   static void barrier2()
65   {
66 #if defined(__SSE2__)
67     __asm__ __volatile__ ("mfence" ::: "memory");
68 #else // defined(__SSE2__)
69     barrier1();
70 #endif // defined(__SSE2__)
71   }
72 };
73
74 } // namespace detail
75 } // namespace asio
76 } // namespace boost
77
78 #include <boost/asio/detail/pop_options.hpp>
79
80 #endif // defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
81
82 #endif // BOOST_ASIO_DETAIL_GCC_X86_FENCED_BLOCK_HPP