mirror of
https://github.com/monero-project/monero.git
synced 2025-08-02 22:06:13 -04:00
Merge pull request #3691
db55263
threadpool: allow constructing an object, and misc tweaks (moneromooo-monero)ce173cb
core: remove threadpool dependency from header (moneromooo-monero)3147468
unit_tests: add threadpool unit test (moneromooo-monero)
This commit is contained in:
commit
cfd66dae4b
6 changed files with 118 additions and 15 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -170,7 +170,6 @@ namespace cryptonote
|
|||
m_last_dns_checkpoints_update(0),
|
||||
m_last_json_checkpoints_update(0),
|
||||
m_disable_dns_checkpoints(false),
|
||||
m_threadpool(tools::threadpool::getInstance()),
|
||||
m_update_download(0),
|
||||
m_nettype(UNDEFINED)
|
||||
{
|
||||
|
@ -681,10 +680,11 @@ namespace cryptonote
|
|||
std::vector<result> results(tx_blobs.size());
|
||||
|
||||
tvc.resize(tx_blobs.size());
|
||||
tools::threadpool& tpool = tools::threadpool::getInstance();
|
||||
tools::threadpool::waiter waiter;
|
||||
std::list<blobdata>::const_iterator it = tx_blobs.begin();
|
||||
for (size_t i = 0; i < tx_blobs.size(); i++, ++it) {
|
||||
m_threadpool.submit(&waiter, [&, i, it] {
|
||||
tpool.submit(&waiter, [&, i, it] {
|
||||
try
|
||||
{
|
||||
results[i].res = handle_incoming_tx_pre(*it, tvc[i], results[i].tx, results[i].hash, results[i].prefix_hash, keeped_by_block, relayed, do_not_relay);
|
||||
|
@ -711,7 +711,7 @@ namespace cryptonote
|
|||
}
|
||||
else
|
||||
{
|
||||
m_threadpool.submit(&waiter, [&, i, it] {
|
||||
tpool.submit(&waiter, [&, i, it] {
|
||||
try
|
||||
{
|
||||
results[i].res = handle_incoming_tx_post(*it, tvc[i], results[i].tx, results[i].hash, results[i].prefix_hash, keeped_by_block, relayed, do_not_relay);
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "cryptonote_protocol/cryptonote_protocol_handler_common.h"
|
||||
#include "storages/portable_storage_template_helper.h"
|
||||
#include "common/download.h"
|
||||
#include "common/threadpool.h"
|
||||
#include "common/command_line.h"
|
||||
#include "tx_pool.h"
|
||||
#include "blockchain.h"
|
||||
|
@ -991,8 +990,6 @@ namespace cryptonote
|
|||
std::unordered_set<crypto::hash> bad_semantics_txes[2];
|
||||
boost::mutex bad_semantics_txes_lock;
|
||||
|
||||
tools::threadpool& m_threadpool;
|
||||
|
||||
enum {
|
||||
UPDATES_DISABLED,
|
||||
UPDATES_NOTIFY,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue