local_free_on_block_exit.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // detail/local_free_on_block_exit.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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. #ifndef BOOST_ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP
  11. #define BOOST_ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
  17. #if !defined(BOOST_ASIO_WINDOWS_APP)
  18. #include <boost/asio/detail/noncopyable.hpp>
  19. #include <boost/asio/detail/socket_types.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace detail {
  24. class local_free_on_block_exit
  25. : private noncopyable
  26. {
  27. public:
  28. // Constructor blocks all signals for the calling thread.
  29. explicit local_free_on_block_exit(void* p)
  30. : p_(p)
  31. {
  32. }
  33. // Destructor restores the previous signal mask.
  34. ~local_free_on_block_exit()
  35. {
  36. ::LocalFree(p_);
  37. }
  38. private:
  39. void* p_;
  40. };
  41. } // namespace detail
  42. } // namespace asio
  43. } // namespace boost
  44. #include <boost/asio/detail/pop_options.hpp>
  45. #endif // !defined(BOOST_ASIO_WINDOWS_APP)
  46. #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
  47. #endif // BOOST_ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP