Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / asio / detail / win_fenced_block.hpp
1 //
2 // detail/win_fenced_block.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 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_WIN_FENCED_BLOCK_HPP
12 #define BOOST_ASIO_DETAIL_WIN_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(BOOST_ASIO_WINDOWS) && !defined(UNDER_CE)
21
22 #include <boost/asio/detail/socket_types.hpp>
23
24 #include <boost/asio/detail/push_options.hpp>
25
26 namespace boost {
27 namespace asio {
28 namespace detail {
29
30 class win_fenced_block
31   : private noncopyable
32 {
33 public:
34   enum half_t { half };
35   enum full_t { full };
36
37   // Constructor for a half fenced block.
38   explicit win_fenced_block(half_t)
39   {
40   }
41
42   // Constructor for a full fenced block.
43   explicit win_fenced_block(full_t)
44   {
45 #if defined(__BORLANDC__)
46     LONG barrier = 0;
47     ::InterlockedExchange(&barrier, 1);
48 #elif defined(BOOST_ASIO_MSVC) \
49   && ((BOOST_ASIO_MSVC < 1400) || !defined(MemoryBarrier))
50 # if defined(_M_IX86)
51 #  pragma warning(push)
52 #  pragma warning(disable:4793)
53     LONG barrier;
54     __asm { xchg barrier, eax }
55 #  pragma warning(pop)
56 # endif // defined(_M_IX86)
57 #else
58     MemoryBarrier();
59 #endif
60   }
61
62   // Destructor.
63   ~win_fenced_block()
64   {
65 #if defined(__BORLANDC__)
66     LONG barrier = 0;
67     ::InterlockedExchange(&barrier, 1);
68 #elif defined(BOOST_ASIO_MSVC) \
69   && ((BOOST_ASIO_MSVC < 1400) || !defined(MemoryBarrier))
70 # if defined(_M_IX86)
71 #  pragma warning(push)
72 #  pragma warning(disable:4793)
73     LONG barrier;
74     __asm { xchg barrier, eax }
75 #  pragma warning(pop)
76 # endif // defined(_M_IX86)
77 #else
78     MemoryBarrier();
79 #endif
80   }
81 };
82
83 } // namespace detail
84 } // namespace asio
85 } // namespace boost
86
87 #include <boost/asio/detail/pop_options.hpp>
88
89 #endif // defined(BOOST_ASIO_WINDOWS) && !defined(UNDER_CE)
90
91 #endif // BOOST_ASIO_DETAIL_WIN_FENCED_BLOCK_HPP