local_free_on_block_exit.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // local_free_on_block_exit.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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 ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP
  11. #define 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 "asio/detail/push_options.hpp"
  16. #include "asio/detail/push_options.hpp"
  17. #include <boost/config.hpp>
  18. #include "asio/detail/pop_options.hpp"
  19. #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
  20. #include "asio/detail/noncopyable.hpp"
  21. #include "asio/detail/socket_types.hpp"
  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. #endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
  44. #include "asio/detail/pop_options.hpp"
  45. #endif // ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP