Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2016-11-27 17:25:22 +0300
committerbubnikv <bubnikv@gmail.com>2016-12-08 16:44:03 +0300
commitd628764da60a518861dd9175e29d7343d69d4af4 (patch)
tree7db0af315897506092c492a342c93dea6d17b982 /xs/src/libslic3r/libslic3r.h
parent73ddd3b438cf4fa499e89705c30daa2fbfdf1c99 (diff)
Minor fixes to parallelize code, cherry picked from @alexrj 5242b3e03ab2b195ba9c7c53fba705a8ed1c7abd
Diffstat (limited to 'xs/src/libslic3r/libslic3r.h')
-rw-r--r--xs/src/libslic3r/libslic3r.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h
index 77d30489d..89db6d81e 100644
--- a/xs/src/libslic3r/libslic3r.h
+++ b/xs/src/libslic3r/libslic3r.h
@@ -4,6 +4,7 @@
// this needs to be included early for MSVC (listing it in Build.PL is not enough)
#include <ostream>
#include <iostream>
+#include <math.h>
#include <queue>
#include <sstream>
#include <cstdio>
@@ -119,9 +120,10 @@ template <class T> void
parallelize(std::queue<T> queue, boost::function<void(T)> func,
int threads_count = boost::thread::hardware_concurrency())
{
+ if (threads_count == 0) threads_count = 2;
boost::mutex queue_mutex;
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.join_all();
}