File indexing completed on 2025-01-18 09:28:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_THREAD_GROUP_HPP
0012 #define BOOST_ASIO_DETAIL_THREAD_GROUP_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/scoped_ptr.hpp>
0020 #include <boost/asio/detail/thread.hpp>
0021
0022 #include <boost/asio/detail/push_options.hpp>
0023
0024 namespace boost {
0025 namespace asio {
0026 namespace detail {
0027
0028 class thread_group
0029 {
0030 public:
0031
0032 thread_group()
0033 : first_(0)
0034 {
0035 }
0036
0037
0038 ~thread_group()
0039 {
0040 join();
0041 }
0042
0043
0044 template <typename Function>
0045 void create_thread(Function f)
0046 {
0047 first_ = new item(f, first_);
0048 }
0049
0050
0051 template <typename Function>
0052 void create_threads(Function f, std::size_t num_threads)
0053 {
0054 for (std::size_t i = 0; i < num_threads; ++i)
0055 create_thread(f);
0056 }
0057
0058
0059 void join()
0060 {
0061 while (first_)
0062 {
0063 first_->thread_.join();
0064 item* tmp = first_;
0065 first_ = first_->next_;
0066 delete tmp;
0067 }
0068 }
0069
0070
0071 bool empty() const
0072 {
0073 return first_ == 0;
0074 }
0075
0076 private:
0077
0078 struct item
0079 {
0080 template <typename Function>
0081 explicit item(Function f, item* next)
0082 : thread_(f),
0083 next_(next)
0084 {
0085 }
0086
0087 boost::asio::detail::thread thread_;
0088 item* next_;
0089 };
0090
0091
0092 item* first_;
0093 };
0094
0095 }
0096 }
0097 }
0098
0099 #include <boost/asio/detail/pop_options.hpp>
0100
0101 #endif