10
10
#include < memory>
11
11
#include < functional>
12
12
#include < asio/io_service.hpp>
13
- #include < boost/function.hpp>
14
- #include < boost/network/tags.hpp>
15
13
#include < boost/scope_exit.hpp>
16
14
#include < boost/network/utils/thread_group.hpp>
17
15
@@ -23,18 +21,18 @@ typedef std::shared_ptr<asio::io_service> io_service_ptr;
23
21
typedef std::shared_ptr<utils::thread_group> worker_threads_ptr;
24
22
typedef std::shared_ptr<asio::io_service::work> sentinel_ptr;
25
23
26
- template < class Tag >
27
- struct basic_thread_pool {
28
- basic_thread_pool (basic_thread_pool const &) = delete ;
29
- basic_thread_pool &operator =(basic_thread_pool ) = delete ;
30
- basic_thread_pool (basic_thread_pool &&) noexcept = default ;
31
- basic_thread_pool &operator =(basic_thread_pool &&) = default ;
24
+ class thread_pool {
25
+ public:
26
+ thread_pool (thread_pool const &) = delete ;
27
+ thread_pool &operator =(thread_pool const & ) = delete ;
28
+ thread_pool (thread_pool &&) noexcept = default ;
29
+ thread_pool &operator =(thread_pool &&) = default ;
32
30
33
- basic_thread_pool () : basic_thread_pool (1 ) {}
31
+ thread_pool () : thread_pool (1 ) {}
34
32
35
- explicit basic_thread_pool (std::size_t threads,
36
- io_service_ptr io_service = io_service_ptr(),
37
- worker_threads_ptr worker_threads = worker_threads_ptr())
33
+ explicit thread_pool (std::size_t threads,
34
+ io_service_ptr io_service = io_service_ptr(),
35
+ worker_threads_ptr worker_threads = worker_threads_ptr())
38
36
: threads_(threads),
39
37
io_service_(std::move(io_service)),
40
38
worker_threads_(std::move(worker_threads)),
@@ -46,7 +44,6 @@ struct basic_thread_pool {
46
44
sentinel_.reset ();
47
45
io_service_.reset ();
48
46
if (worker_threads_.get ()) {
49
- // worker_threads_->interrupt_all();
50
47
worker_threads_->join_all ();
51
48
}
52
49
worker_threads_.reset ();
@@ -67,7 +64,7 @@ struct basic_thread_pool {
67
64
}
68
65
69
66
for (std::size_t counter = 0 ; counter < threads_; ++counter) {
70
- worker_threads_->create_thread ([=] () { io_service_->run (); });
67
+ worker_threads_->create_thread ([=]() { io_service_->run (); });
71
68
}
72
69
73
70
commit = true ;
@@ -77,18 +74,16 @@ struct basic_thread_pool {
77
74
78
75
void post (std::function<void ()> f) { io_service_->post (f); }
79
76
80
- ~basic_thread_pool () throw () {
77
+ ~thread_pool () {
81
78
sentinel_.reset ();
82
79
try {
83
80
worker_threads_->join_all ();
84
- }
85
- catch (...) {
86
- BOOST_ASSERT (false &&
87
- " A handler was not supposed to throw, but one did." );
81
+ } catch (const std::exception &) {
82
+ assert (!" A handler was not supposed to throw, but one did." );
88
83
}
89
84
}
90
85
91
- void swap (basic_thread_pool &other) {
86
+ void swap (thread_pool &other) {
92
87
using std::swap;
93
88
swap (other.threads_ , threads_);
94
89
swap (other.io_service_ , io_service_);
@@ -101,16 +96,9 @@ struct basic_thread_pool {
101
96
io_service_ptr io_service_;
102
97
worker_threads_ptr worker_threads_;
103
98
sentinel_ptr sentinel_;
104
-
105
99
};
106
100
107
- template <class T >
108
- void swap (basic_thread_pool<T> &a, basic_thread_pool<T> &b) {
109
- a.swap (b);
110
- }
111
-
112
- typedef basic_thread_pool<tags::default_> thread_pool;
113
-
101
+ void swap (thread_pool &a, thread_pool &b) { a.swap (b); }
114
102
} // namespace utils
115
103
} // namespace network
116
104
} // namespace boost
0 commit comments