mirror of
https://github.com/monero-project/monero.git
synced 2025-08-13 07:25:30 -04:00
threadpool: allow constructing an object, and misc tweaks
use unsigned int to avoid having to range check negative numbers, use const where possible, don't needlessly create empty objects, use std::move where possible
This commit is contained in:
parent
6b9d9f56a1
commit
db55263b4c
2 changed files with 13 additions and 9 deletions
|
@ -39,11 +39,11 @@ static __thread int depth = 0;
|
|||
|
||||
namespace tools
|
||||
{
|
||||
threadpool::threadpool() : running(true), active(0) {
|
||||
threadpool::threadpool(unsigned int max_threads) : running(true), active(0) {
|
||||
boost::thread::attributes attrs;
|
||||
attrs.set_stack_size(THREAD_STACK_SIZE);
|
||||
max = tools::get_max_concurrency();
|
||||
size_t i = max;
|
||||
max = max_threads ? max_threads : tools::get_max_concurrency();
|
||||
unsigned int i = max;
|
||||
while(i--) {
|
||||
threads.push_back(boost::thread(attrs, boost::bind(&threadpool::run, this)));
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void threadpool::submit(waiter *obj, std::function<void()> f) {
|
|||
}
|
||||
}
|
||||
|
||||
int threadpool::get_max_concurrency() {
|
||||
unsigned int threadpool::get_max_concurrency() const {
|
||||
return max;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue