]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/impl/thread_pool.ipp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / asio / impl / thread_pool.ipp
1 //
2 // impl/thread_pool.ipp
3 // ~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2018 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_IMPL_THREAD_POOL_IPP
12 #define BOOST_ASIO_IMPL_THREAD_POOL_IPP
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 #include <boost/asio/thread_pool.hpp>
20
21 #include <boost/asio/detail/push_options.hpp>
22
23 namespace boost {
24 namespace asio {
25
26 struct thread_pool::thread_function
27 {
28 detail::scheduler* scheduler_;
29
30 void operator()()
31 {
32 boost::system::error_code ec;
33 scheduler_->run(ec);
34 }
35 };
36
37 thread_pool::thread_pool()
38 : scheduler_(use_service<detail::scheduler>(*this))
39 {
40 scheduler_.work_started();
41
42 thread_function f = { &scheduler_ };
43 std::size_t num_threads = detail::thread::hardware_concurrency() * 2;
44 threads_.create_threads(f, num_threads ? num_threads : 2);
45 }
46
47 thread_pool::thread_pool(std::size_t num_threads)
48 : scheduler_(use_service<detail::scheduler>(*this))
49 {
50 scheduler_.work_started();
51
52 thread_function f = { &scheduler_ };
53 threads_.create_threads(f, num_threads);
54 }
55
56 thread_pool::~thread_pool()
57 {
58 stop();
59 join();
60 }
61
62 void thread_pool::stop()
63 {
64 scheduler_.stop();
65 }
66
67 void thread_pool::join()
68 {
69 scheduler_.work_finished();
70 threads_.join();
71 }
72
73 } // namespace asio
74 } // namespace boost
75
76 #include <boost/asio/detail/pop_options.hpp>
77
78 #endif // BOOST_ASIO_IMPL_THREAD_POOL_IPP