]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/std_thread.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
5 | // Copyright (c) 2003-2016 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_STD_THREAD_HPP | |
12 | #define BOOST_ASIO_DETAIL_STD_THREAD_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_HAS_STD_THREAD) | |
21 | ||
22 | #include <thread> | |
23 | #include <boost/asio/detail/noncopyable.hpp> | |
24 | ||
25 | #include <boost/asio/detail/push_options.hpp> | |
26 | ||
27 | namespace boost { | |
28 | namespace asio { | |
29 | namespace detail { | |
30 | ||
31 | class std_thread | |
32 | : private noncopyable | |
33 | { | |
34 | public: | |
35 | // Constructor. | |
36 | template <typename Function> | |
37 | std_thread(Function f, unsigned int = 0) | |
38 | : thread_(f) | |
39 | { | |
40 | } | |
41 | ||
42 | // Destructor. | |
43 | ~std_thread() | |
44 | { | |
45 | join(); | |
46 | } | |
47 | ||
48 | // Wait for the thread to exit. | |
49 | void join() | |
50 | { | |
51 | if (thread_.joinable()) | |
52 | thread_.join(); | |
53 | } | |
54 | ||
55 | private: | |
56 | std::thread thread_; | |
57 | }; | |
58 | ||
59 | } // namespace detail | |
60 | } // namespace asio | |
61 | } // namespace boost | |
62 | ||
63 | #include <boost/asio/detail/pop_options.hpp> | |
64 | ||
65 | #endif // defined(BOOST_ASIO_HAS_STD_THREAD) | |
66 | ||
67 | #endif // BOOST_ASIO_DETAIL_STD_THREAD_HPP |