1
1
// Copyright 2010 Dean Michael Berris.
2
2
// Copyright 2012 Google, Inc.
3
- // Copyright (c) Glyn Matthews 2012, 2013.
3
+ // Copyright (c) Glyn Matthews 2012, 2013, 2014 .
4
4
// Distributed under the Boost Software License, Version 1.0.
5
5
// (See accompanying file LICENSE_1_0.txt or copy at
6
6
// http://www.boost.org/LICENSE_1_0.txt)
7
7
8
- #ifndef NETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020
9
- #define NETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020
8
+ #ifndef NETWORK_CONCURRENCY_THREAD_POOL_INC
9
+ #define NETWORK_CONCURRENCY_THREAD_POOL_INC
10
+
11
+ /* *
12
+ * \defgroup concurrency Basic Concurrency Types
13
+ *
14
+ * This module contains a simple concurrency types for use inside the
15
+ * cpp-netlib network libraries.
16
+ *
17
+ * \file
18
+ * \brief Contains a thread_pool type.
19
+ */
10
20
11
21
#include < cstddef>
12
22
#include < thread>
@@ -22,20 +32,62 @@ namespace network {
22
32
typedef std::shared_ptr<std::vector<std::thread>> worker_threads_ptr;
23
33
typedef std::shared_ptr<boost::asio::io_service::work> sentinel_ptr;
24
34
25
- struct thread_pool {
26
- thread_pool (std::size_t threads = 1 ,
35
+ /* *
36
+ * \ingroup concurrency
37
+ * \class thread_pool network/concurrency/thread_pool.hpp
38
+ * \brief A very simple thread pool.
39
+ */
40
+ class thread_pool {
41
+
42
+ thread_pool (thread_pool const &) = delete ;
43
+ thread_pool& operator =(thread_pool const &) = delete ;
44
+
45
+ public:
46
+
47
+ /* *
48
+ * \brief Constructor.
49
+ * \param thread_count The number of threads in the thread pool.
50
+ * \param io_service An external io_service.
51
+ * \param worker_threads An external thread pool.
52
+ */
53
+ thread_pool (std::size_t thread_count = 1 ,
27
54
io_service_ptr io_service = io_service_ptr(),
28
55
std::vector<std::thread> worker_threads = std::vector<std::thread>());
29
- thread_pool (thread_pool const &) = delete ;
30
- thread_pool (thread_pool && other);
56
+
57
+ /* *
58
+ * \brief Move constuctor.
59
+ * \param other The other thread_pool object.
60
+ */
61
+ thread_pool (thread_pool&& other);
62
+
63
+ /* *
64
+ * \brief Destructor.
65
+ */
31
66
~thread_pool ();
32
67
33
- thread_pool& operator =(thread_pool const &) = delete ;
34
- thread_pool& operator =(thread_pool && other);
68
+ /* *
69
+ * \brief Swap function.
70
+ * \param other The other thread_pool object.
71
+ */
72
+ void swap (thread_pool& other);
35
73
74
+ /* *
75
+ * \brief Move assignment operator.
76
+ * \param other The other thread_pool object.
77
+ */
78
+ thread_pool& operator =(thread_pool&& other);
79
+
80
+ /* *
81
+ * \brief Returns the number of threads in the thread pool.
82
+ * \returns The number of threads in the thread pool.
83
+ */
36
84
std::size_t const thread_count () const ;
37
- void post (std::function<void ()> f);
38
- void swap (thread_pool& other);
85
+
86
+ /* *
87
+ * \brief Posts a task to the thread pool.
88
+ * \param task The task to be executed.
89
+ */
90
+ void post (std::function<void ()> task);
39
91
40
92
private:
41
93
@@ -52,4 +104,4 @@ namespace network {
52
104
} // namespace concurrency
53
105
} // namespace network
54
106
55
- #endif /* NETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020 */
107
+ #endif // NETWORK_CONCURRENCY_THREAD_POOL_INC
0 commit comments