Permalink
Browse files

Updated thread pool documentation.

  • Loading branch information...
1 parent 4d2389b commit 43efa98c2d211a3dac8729d3fe1eaefe1a26dde6 @glynos glynos committed Jan 25, 2014
View
9 Doxyfile.in
@@ -130,7 +130,8 @@ FULL_PATH_NAMES = YES
STRIP_FROM_PATH = @CMAKE_CURRENT_SOURCE_DIR@/error/src/ \
@CMAKE_CURRENT_SOURCE_DIR@/uri/src/ \
- @CMAKE_CURRENT_SOURCE_DIR@/http/src/
+ @CMAKE_CURRENT_SOURCE_DIR@/http/src/ \
+ @CMAKE_CURRENT_SOURCE_DIR@/concurrency/src/
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
# the path mentioned in the documentation of a class, which tells
@@ -652,7 +653,8 @@ WARN_LOGFILE =
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/error/ \
@CMAKE_CURRENT_SOURCE_DIR@/uri/src/network/ \
- @CMAKE_CURRENT_SOURCE_DIR@/http/src/network/http/
+ @CMAKE_CURRENT_SOURCE_DIR@/http/src/network/http/ \
+ @CMAKE_CURRENT_SOURCE_DIR@/concurrency/src/network/
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
@@ -849,7 +851,8 @@ COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX = @CMAKE_CURRENT_SOURCE_DIR@/error/src/ \
@CMAKE_CURRENT_SOURCE_DIR@/uri/src/ \
- @CMAKE_CURRENT_SOURCE_DIR@/http/src/
+ @CMAKE_CURRENT_SOURCE_DIR@/http/src/ \
+ @CMAKE_CURRENT_SOURCE_DIR@/concurrency/src/
#---------------------------------------------------------------------------
# configuration options related to the HTML output
View
76 concurrency/src/network/concurrency/thread_pool.hpp
@@ -1,12 +1,22 @@
// Copyright 2010 Dean Michael Berris.
// Copyright 2012 Google, Inc.
-// Copyright (c) Glyn Matthews 2012, 2013.
+// Copyright (c) Glyn Matthews 2012, 2013, 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef NETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020
-#define NETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020
+#ifndef NETWORK_CONCURRENCY_THREAD_POOL_INC
+#define NETWORK_CONCURRENCY_THREAD_POOL_INC
+
+/**
+ * \defgroup concurrency Basic Concurrency Types
+ *
+ * This module contains a simple concurrency types for use inside the
+ * cpp-netlib network libraries.
+ *
+ * \file
+ * \brief Contains a thread_pool type.
+ */
#include <cstddef>
#include <thread>
@@ -22,20 +32,62 @@ namespace network {
typedef std::shared_ptr<std::vector<std::thread>> worker_threads_ptr;
typedef std::shared_ptr<boost::asio::io_service::work> sentinel_ptr;
- struct thread_pool {
- thread_pool(std::size_t threads = 1,
+ /**
+ * \ingroup concurrency
+ * \class thread_pool network/concurrency/thread_pool.hpp
+ * \brief A very simple thread pool.
+ */
+ class thread_pool {
+
+ thread_pool(thread_pool const&) = delete;
+ thread_pool& operator=(thread_pool const&) = delete;
+
+ public:
+
+ /**
+ * \brief Constructor.
+ * \param thread_count The number of threads in the thread pool.
+ * \param io_service An external io_service.
+ * \param worker_threads An external thread pool.
+ */
+ thread_pool(std::size_t thread_count = 1,
io_service_ptr io_service = io_service_ptr(),
std::vector<std::thread> worker_threads = std::vector<std::thread>());
- thread_pool(thread_pool const&) = delete;
- thread_pool(thread_pool && other);
+
+ /**
+ * \brief Move constuctor.
+ * \param other The other thread_pool object.
+ */
+ thread_pool(thread_pool&& other);
+
+ /**
+ * \brief Destructor.
+ */
~thread_pool();
- thread_pool& operator=(thread_pool const&) = delete;
- thread_pool& operator=(thread_pool && other);
+ /**
+ * \brief Swap function.
+ * \param other The other thread_pool object.
+ */
+ void swap(thread_pool& other);
+ /**
+ * \brief Move assignment operator.
+ * \param other The other thread_pool object.
+ */
+ thread_pool& operator=(thread_pool&& other);
+
+ /**
+ * \brief Returns the number of threads in the thread pool.
+ * \returns The number of threads in the thread pool.
+ */
std::size_t const thread_count() const;
- void post(std::function<void()> f);
- void swap(thread_pool& other);
+
+ /**
+ * \brief Posts a task to the thread pool.
+ * \param task The task to be executed.
+ */
+ void post(std::function<void()> task);
private:
@@ -52,4 +104,4 @@ namespace network {
} // namespace concurrency
} // namespace network
-#endif /* NETWORK_CONCURRENCY_THREAD_POOL_HPP_20101020 */
+#endif // NETWORK_CONCURRENCY_THREAD_POOL_INC
View
14 concurrency/src/network/concurrency/thread_pool.ipp
@@ -17,10 +17,10 @@ namespace network {
namespace concurrency {
struct thread_pool::impl {
- impl(std::size_t threads = 1,
+ impl(std::size_t thread_count = 1,
io_service_ptr io_service = io_service_ptr(),
std::vector<std::thread> worker_threads = std::vector<std::thread>())
- : threads_(threads),
+ : thread_count_(thread_count),
io_service_(io_service),
worker_threads_(std::move(worker_threads)),
sentinel_() {
@@ -49,7 +49,7 @@ namespace network {
}
auto local_io_service = io_service_;
- for (std::size_t counter = 0; counter < threads_; ++counter) {
+ for (std::size_t counter = 0; counter < thread_count_; ++counter) {
worker_threads_.emplace_back([local_io_service]() {
local_io_service->run();
});
@@ -71,23 +71,23 @@ namespace network {
}
}
- std::size_t threads_;
+ std::size_t thread_count_;
io_service_ptr io_service_;
std::vector<std::thread> worker_threads_;
sentinel_ptr sentinel_;
};
- thread_pool::thread_pool(std::size_t threads,
+ thread_pool::thread_pool(std::size_t thread_count,
io_service_ptr io_service,
std::vector<std::thread> worker_threads)
: pimpl_(new (std::nothrow)
- impl(threads, io_service, std::move(worker_threads))) {
+ impl(thread_count, io_service, std::move(worker_threads))) {
}
std::size_t const thread_pool::thread_count() const {
- return pimpl_->threads_;
+ return pimpl_->thread_count_;
}
void thread_pool::post(std::function<void()> f) {

0 comments on commit 43efa98

Please sign in to comment.