local_free_on_block_exit.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // detail/local_free_on_block_exit.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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/config.hpp"
  16. #if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
  17. #if !defined(ASIO_WINDOWS_APP)
  18. #include "asio/detail/noncopyable.hpp"
  19. #include "asio/detail/socket_types.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. class local_free_on_block_exit
  24. : private noncopyable
  25. {
  26. public:
  27. // Constructor blocks all signals for the calling thread.
  28. explicit local_free_on_block_exit(void* p)
  29. : p_(p)
  30. {
  31. }
  32. // Destructor restores the previous signal mask.
  33. ~local_free_on_block_exit()
  34. {
  35. ::LocalFree(p_);
  36. }
  37. private:
  38. void* p_;
  39. };
  40. } // namespace detail
  41. } // namespace asio
  42. #include "asio/detail/pop_options.hpp"
  43. #endif // !defined(ASIO_WINDOWS_APP)
  44. #endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
  45. #endif // ASIO_DETAIL_LOCAL_FREE_ON_BLOCK_EXIT_HPP