std_thread.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // detail/std_thread.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. #ifndef BOOST_ASIO_DETAIL_STD_THREAD_HPP
  11. #define BOOST_ASIO_DETAIL_STD_THREAD_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_HAS_STD_THREAD)
  17. #include <thread>
  18. #include <boost/asio/detail/noncopyable.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. namespace detail {
  23. class std_thread
  24. : private noncopyable
  25. {
  26. public:
  27. // Constructor.
  28. template <typename Function>
  29. std_thread(Function f, unsigned int = 0)
  30. : thread_(f)
  31. {
  32. }
  33. // Destructor.
  34. ~std_thread()
  35. {
  36. join();
  37. }
  38. // Wait for the thread to exit.
  39. void join()
  40. {
  41. if (thread_.joinable())
  42. thread_.join();
  43. }
  44. private:
  45. std::thread thread_;
  46. };
  47. } // namespace detail
  48. } // namespace asio
  49. } // namespace boost
  50. #include <boost/asio/detail/pop_options.hpp>
  51. #endif // defined(BOOST_ASIO_HAS_STD_THREAD)
  52. #endif // BOOST_ASIO_DETAIL_STD_THREAD_HPP