the default pool thread number is thread hw concurrency

This commit is contained in:
Jinhao 2018-08-25 06:53:11 +08:00
parent e0ba1c7d8a
commit e8e7ad543c
3 changed files with 20 additions and 11 deletions

View File

@ -1,6 +1,6 @@
/* /*
* A Thread Pool Implementation * A Thread Pool Implementation
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -13,10 +13,14 @@
#ifndef NANA_THREADS_POOL_HPP #ifndef NANA_THREADS_POOL_HPP
#define NANA_THREADS_POOL_HPP #define NANA_THREADS_POOL_HPP
#include <nana/c++defines.hpp>
#include <nana/traits.hpp> #include <nana/traits.hpp>
#include <functional> #include <functional>
#include <cstddef> #include <cstddef>
#ifndef STD_THREAD_NOT_SUPPORTED
# include <thread>
#endif
namespace nana{ namespace nana{
/// Some mutex classes for synchronizing. /// Some mutex classes for synchronizing.
@ -58,9 +62,12 @@ namespace threads
pool(const pool&) = delete; pool(const pool&) = delete;
pool& operator=(const pool&) = delete; pool& operator=(const pool&) = delete;
public: public:
pool(); ///< Creates a group of threads. #ifndef STD_THREAD_NOT_SUPPORTED
pool(unsigned thread_number = std::thread::hardware_concurrency()); ///< Creates a group of threads.
#else
pool(unsigned thread_number = 0);
#endif
pool(pool&&); pool(pool&&);
pool(std::size_t thread_number); ///< Creates a number of threads specifed by thread_number.
~pool(); ///< waits for the all running tasks till they are finished and skips all the queued tasks. ~pool(); ///< waits for the all running tasks till they are finished and skips all the queued tasks.
pool& operator=(pool&&); pool& operator=(pool&&);

View File

@ -2086,7 +2086,7 @@ namespace nana{ namespace widgets
void text_editor::copy() const void text_editor::copy() const
{ {
//Stops copying text if the text_editor is masked. //Disallows copying text if the text_editor is masked.
if (mask_char_) if (mask_char_)
return; return;

View File

@ -351,10 +351,17 @@ namespace threads
}container_; }container_;
};//end class impl };//end class impl
pool::pool() #ifndef STD_THREAD_NOT_SUPPORTED
: impl_(new impl(4)) pool::pool(unsigned thread_number)
: impl_(new impl(thread_number ? thread_number : std::thread::hardware_concurrency()))
{ {
} }
#else
pool::pool(unsigned thread_number)
: impl_(new impl(0))
{
}
#endif
pool::pool(pool&& other) pool::pool(pool&& other)
: pool() : pool()
@ -362,11 +369,6 @@ namespace threads
std::swap(impl_, other.impl_); std::swap(impl_, other.impl_);
} }
pool::pool(std::size_t thread_number)
: impl_(new impl(thread_number))
{
}
pool& pool::operator=(pool&& other) pool& pool::operator=(pool&& other)
{ {
if(this != &other) if(this != &other)