Minor fixes to parallelize code, cherry picked from @alexrj 5242b3e03ab2b195ba9c7c53fba705a8ed1c7abd
This commit is contained in:
parent
73ddd3b438
commit
d628764da6
2 changed files with 9 additions and 3 deletions
|
@ -1292,8 +1292,12 @@ PrintConfigDef::PrintConfigDef()
|
||||||
def->readonly = true;
|
def->readonly = true;
|
||||||
def->min = 1;
|
def->min = 1;
|
||||||
def->max = 16;
|
def->max = 16;
|
||||||
def->default_value = new ConfigOptionInt((boost::thread::hardware_concurrency() == 0) ? 2 : boost::thread::hardware_concurrency());
|
{
|
||||||
|
int threads = boost::thread::hardware_concurrency();
|
||||||
|
if (threads == 0) threads = 2;
|
||||||
|
def->default_value = new ConfigOptionInt(threads);
|
||||||
|
}
|
||||||
|
|
||||||
def = this->add("toolchange_gcode", coString);
|
def = this->add("toolchange_gcode", coString);
|
||||||
def->label = "Tool change G-code";
|
def->label = "Tool change G-code";
|
||||||
def->tooltip = "This custom code is inserted right before every extruder change. Note that you can use placeholder variables for all Slic3r settings as well as [previous_extruder] and [next_extruder].";
|
def->tooltip = "This custom code is inserted right before every extruder change. Note that you can use placeholder variables for all Slic3r settings as well as [previous_extruder] and [next_extruder].";
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
// this needs to be included early for MSVC (listing it in Build.PL is not enough)
|
// this needs to be included early for MSVC (listing it in Build.PL is not enough)
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <math.h>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -119,9 +120,10 @@ template <class T> void
|
||||||
parallelize(std::queue<T> queue, boost::function<void(T)> func,
|
parallelize(std::queue<T> queue, boost::function<void(T)> func,
|
||||||
int threads_count = boost::thread::hardware_concurrency())
|
int threads_count = boost::thread::hardware_concurrency())
|
||||||
{
|
{
|
||||||
|
if (threads_count == 0) threads_count = 2;
|
||||||
boost::mutex queue_mutex;
|
boost::mutex queue_mutex;
|
||||||
boost::thread_group workers;
|
boost::thread_group workers;
|
||||||
for (int i = 0; i < threads_count; i++)
|
for (int i = 0; i < fminf(threads_count, queue.size()); i++)
|
||||||
workers.add_thread(new boost::thread(&_parallelize_do<T>, &queue, &queue_mutex, func));
|
workers.add_thread(new boost::thread(&_parallelize_do<T>, &queue, &queue_mutex, func));
|
||||||
workers.join_all();
|
workers.join_all();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue