]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/std_thread.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / detail / std_thread.hpp
1 //
2 // detail/std_thread.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 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 // Get number of CPUs.
56 static std::size_t hardware_concurrency()
57 {
58 return std::thread::hardware_concurrency();
59 }
60
61 private:
62 std::thread thread_;
63 };
64
65 } // namespace detail
66 } // namespace asio
67 } // namespace boost
68
69 #include <boost/asio/detail/pop_options.hpp>
70
71 #endif // defined(BOOST_ASIO_HAS_STD_THREAD)
72
73 #endif // BOOST_ASIO_DETAIL_STD_THREAD_HPP