mirror of
https://github.com/monero-project/monero.git
synced 2025-08-10 22:30:14 -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
|
@ -46,6 +46,9 @@ public:
|
|||
static threadpool instance;
|
||||
return instance;
|
||||
}
|
||||
static threadpool *getNewForUnitTests(unsigned max_threads = 0) {
|
||||
return new threadpool(max_threads);
|
||||
}
|
||||
|
||||
// The waiter lets the caller know when all of its
|
||||
// tasks are completed.
|
||||
|
@ -66,11 +69,12 @@ public:
|
|||
// task to finish.
|
||||
void submit(waiter *waiter, std::function<void()> f);
|
||||
|
||||
int get_max_concurrency();
|
||||
unsigned int get_max_concurrency() const;
|
||||
|
||||
~threadpool();
|
||||
|
||||
private:
|
||||
threadpool();
|
||||
~threadpool();
|
||||
threadpool(unsigned int max_threads = 0);
|
||||
typedef struct entry {
|
||||
waiter *wo;
|
||||
std::function<void()> f;
|
||||
|
@ -79,8 +83,8 @@ public:
|
|||
boost::condition_variable has_work;
|
||||
boost::mutex mutex;
|
||||
std::vector<boost::thread> threads;
|
||||
int active;
|
||||
int max;
|
||||
unsigned int active;
|
||||
unsigned int max;
|
||||
bool running;
|
||||
void run();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue