1 //
2 // detail/local_free_on_block_exit.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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_LOCAL_FREE_ON_BLOCK_EXIT_HPP
12 #define BOOST_ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_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(__CYGWIN__)
21 
22 #include <boost/asio/detail/noncopyable.hpp>
23 #include <boost/asio/detail/socket_types.hpp>
24 
25 #include <boost/asio/detail/push_options.hpp>
26 
27 namespace boost {
28 namespace asio {
29 namespace detail {
30 
31 class local_free_on_block_exit
32   : private noncopyable
33 {
34 public:
35   // Constructor blocks all signals for the calling thread.
local_free_on_block_exit(void * p)36   explicit local_free_on_block_exit(void* p)
37     : p_(p)
38   {
39   }
40 
41   // Destructor restores the previous signal mask.
~local_free_on_block_exit()42   ~local_free_on_block_exit()
43   {
44     ::LocalFree(p_);
45   }
46 
47 private:
48   void* p_;
49 };
50 
51 } // namespace detail
52 } // namespace asio
53 } // namespace boost
54 
55 #include <boost/asio/detail/pop_options.hpp>
56 
57 #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
58 
59 #endif // BOOST_ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP
60