Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop deprecated TBB components #6590

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libslic3r/Execution/ExecutionTBB.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef EXECUTIONTBB_HPP
#define EXECUTIONTBB_HPP

#include <mutex>

#include <tbb/spin_mutex.h>
#include <tbb/mutex.h>
#include <tbb/parallel_for.h>
#include <tbb/parallel_reduce.h>
#include <tbb/task_arena.h>
Expand Down Expand Up @@ -34,7 +35,7 @@ template<> struct execution::Traits<ExecutionTBB> {

public:
using SpinningMutex = tbb::spin_mutex;
using BlockingMutex = tbb::mutex;
using BlockingMutex = std::mutex;

template<class It, class Fn>
static void for_each(const ExecutionTBB &,
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PrintRegion::PrintRegion(PrintRegionConfig &&config) : PrintRegion(std::move(con

void Print::clear()
{
tbb::mutex::scoped_lock lock(this->state_mutex());
std::scoped_lock<std::mutex> lock(this->state_mutex());
// The following call should stop background processing if it is running.
this->invalidate_all_steps();
for (PrintObject *object : m_objects)
Expand Down Expand Up @@ -252,7 +252,7 @@ bool Print::is_step_done(PrintObjectStep step) const
{
if (m_objects.empty())
return false;
tbb::mutex::scoped_lock lock(this->state_mutex());
std::scoped_lock<std::mutex> lock(this->state_mutex());
for (const PrintObject *object : m_objects)
if (! object->is_step_done_unguarded(step))
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PrintApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
update_apply_status(false);

// Grab the lock for the Print / PrintObject milestones.
tbb::mutex::scoped_lock lock(this->state_mutex());
std::scoped_lock<std::mutex> lock(this->state_mutex());

// The following call may stop the background processing.
if (! print_diff.empty())
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/PrintBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void PrintBase::status_update_warnings(int step, PrintStateBase::WarningLevel /*
printf("%s warning: %s\n", print_object ? "print_object" : "print", message.c_str());
}

tbb::mutex& PrintObjectBase::state_mutex(PrintBase *print)
std::mutex& PrintObjectBase::state_mutex(PrintBase *print)
{
return print->state_mutex();
}
Expand Down
40 changes: 18 additions & 22 deletions src/libslic3r/PrintBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
#include <vector>
#include <string>
#include <functional>

// tbb/mutex.h includes Windows, which in turn defines min/max macros. Convince Windows.h to not define these min/max macros.
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include "tbb/mutex.h"
#include <atomic>
#include <mutex>

#include "ObjectID.hpp"
#include "Model.hpp"
Expand Down Expand Up @@ -84,23 +80,23 @@ class PrintState : public PrintStateBase
public:
PrintState() {}

StateWithTimeStamp state_with_timestamp(StepType step, tbb::mutex &mtx) const {
tbb::mutex::scoped_lock lock(mtx);
StateWithTimeStamp state_with_timestamp(StepType step, std::mutex &mtx) const {
std::scoped_lock<std::mutex> lock(mtx);
StateWithTimeStamp state = m_state[step];
return state;
}

StateWithWarnings state_with_warnings(StepType step, tbb::mutex &mtx) const {
tbb::mutex::scoped_lock lock(mtx);
StateWithWarnings state_with_warnings(StepType step, std::mutex &mtx) const {
std::scoped_lock<std::mutex> lock(mtx);
StateWithWarnings state = m_state[step];
return state;
}

bool is_started(StepType step, tbb::mutex &mtx) const {
bool is_started(StepType step, std::mutex &mtx) const {
return this->state_with_timestamp(step, mtx).state == STARTED;
}

bool is_done(StepType step, tbb::mutex &mtx) const {
bool is_done(StepType step, std::mutex &mtx) const {
return this->state_with_timestamp(step, mtx).state == DONE;
}

Expand All @@ -121,8 +117,8 @@ class PrintState : public PrintStateBase
// This is necessary to block until the Print::apply() updates its state, which may
// influence the processing step being entered.
template<typename ThrowIfCanceled>
bool set_started(StepType step, tbb::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
tbb::mutex::scoped_lock lock(mtx);
bool set_started(StepType step, std::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
std::scoped_lock<std::mutex> lock(mtx);
// If canceled, throw before changing the step state.
throw_if_canceled();
#ifndef NDEBUG
Expand Down Expand Up @@ -154,8 +150,8 @@ class PrintState : public PrintStateBase
// Timestamp when this stepentered the DONE state.
// bool indicates whether the UI has to update the slicing warnings of this step or not.
template<typename ThrowIfCanceled>
std::pair<TimeStamp, bool> set_done(StepType step, tbb::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
tbb::mutex::scoped_lock lock(mtx);
std::pair<TimeStamp, bool> set_done(StepType step, std::mutex &mtx, ThrowIfCanceled throw_if_canceled) {
std::scoped_lock<std::mutex> lock(mtx);
// If canceled, throw before changing the step state.
throw_if_canceled();
assert(m_state[step].state == STARTED);
Expand Down Expand Up @@ -266,9 +262,9 @@ class PrintState : public PrintStateBase
// Return value:
// Current milestone (StepType).
// bool indicates whether the UI has to be updated or not.
std::pair<StepType, bool> active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id, tbb::mutex &mtx)
std::pair<StepType, bool> active_step_add_warning(PrintStateBase::WarningLevel warning_level, const std::string &message, int message_id, std::mutex &mtx)
{
tbb::mutex::scoped_lock lock(mtx);
std::scoped_lock<std::mutex> lock(mtx);
assert(m_step_active != -1);
StateWithWarnings &state = m_state[m_step_active];
assert(state.state == STARTED);
Expand Down Expand Up @@ -314,7 +310,7 @@ class PrintObjectBase : public ObjectBase
PrintObjectBase(ModelObject *model_object) : m_model_object(model_object) {}
virtual ~PrintObjectBase() {}
// Declared here to allow access from PrintBase through friendship.
static tbb::mutex& state_mutex(PrintBase *print);
static std::mutex& state_mutex(PrintBase *print);
static std::function<void()> cancel_callback(PrintBase *print);
// Notify UI about a new warning of a milestone "step" on this PrintObjectBase.
// The UI will be notified by calling a status callback registered on print.
Expand Down Expand Up @@ -475,7 +471,7 @@ class PrintBase : public ObjectBase
friend class PrintObjectBase;
friend class BackgroundSlicingProcess;

tbb::mutex& state_mutex() const { return m_state_mutex; }
std::mutex& state_mutex() const { return m_state_mutex; }
std::function<void()> cancel_callback() { return m_cancel_callback; }
void call_cancel_callback() { m_cancel_callback(); }
// Notify UI about a new warning of a milestone "step" on this PrintBase.
Expand All @@ -502,15 +498,15 @@ class PrintBase : public ObjectBase
status_callback_type m_status_callback;

private:
tbb::atomic<CancelStatus> m_cancel_status;
std::atomic<CancelStatus> m_cancel_status;

// Callback to be evoked to stop the background processing before a state is updated.
cancel_callback_type m_cancel_callback = [](){};

// Mutex used for synchronization of the worker thread with the UI thread:
// The mutex will be used to guard the worker thread against entering a stage
// while the data influencing the stage is modified.
mutable tbb::mutex m_state_mutex;
mutable std::mutex m_state_mutex;

friend PrintTryCancel;
};
Expand Down
1 change: 0 additions & 1 deletion src/libslic3r/PrintObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <boost/log/trivial.hpp>

#include <tbb/parallel_for.h>
#include <tbb/atomic.h>

#include <Shiny/Shiny.h>

Expand Down
3 changes: 0 additions & 3 deletions src/libslic3r/SLA/SupportTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#include <libnest2d/optimizers/nlopt/genetic.hpp>
#include <libnest2d/optimizers/nlopt/subplex.hpp>
#include <boost/log/trivial.hpp>
#include <tbb/parallel_for.h>
#include <tbb/mutex.h>
#include <tbb/spin_mutex.h>
#include <libslic3r/I18N.hpp>

//! macro used to mark string used at localization,
Expand Down
10 changes: 4 additions & 6 deletions src/libslic3r/SLAPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <libnest2d/tools/benchmark.h>
#endif

//#include <tbb/spin_mutex.h>//#include "tbb/mutex.h"

#include "I18N.hpp"

//! macro used to mark string used at localization,
Expand Down Expand Up @@ -118,7 +116,7 @@ bool validate_pad(const TriangleMesh &pad, const sla::PadConfig &pcfg)

void SLAPrint::clear()
{
tbb::mutex::scoped_lock lock(this->state_mutex());
std::scoped_lock<std::mutex> lock(this->state_mutex());
// The following call should stop background processing if it is running.
this->invalidate_all_steps();
for (SLAPrintObject *object : m_objects)
Expand Down Expand Up @@ -212,7 +210,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
update_apply_status(false);

// Grab the lock for the Print / PrintObject milestones.
tbb::mutex::scoped_lock lock(this->state_mutex());
std::scoped_lock<std::mutex> lock(this->state_mutex());

// The following call may stop the background processing.
bool invalidate_all_model_objects = false;
Expand Down Expand Up @@ -514,7 +512,7 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con
void SLAPrint::set_task(const TaskParams &params)
{
// Grab the lock for the Print / PrintObject milestones.
tbb::mutex::scoped_lock lock(this->state_mutex());
std::scoped_lock<std::mutex> lock(this->state_mutex());

int n_object_steps = int(params.to_object_step) + 1;
if (n_object_steps == 0)
Expand Down Expand Up @@ -884,7 +882,7 @@ bool SLAPrint::is_step_done(SLAPrintObjectStep step) const
{
if (m_objects.empty())
return false;
tbb::mutex::scoped_lock lock(this->state_mutex());
std::scoped_lock<std::mutex> lock(this->state_mutex());
for (const SLAPrintObject *object : m_objects)
if (! object->is_step_done_unguarded(step))
return false;
Expand Down
1 change: 0 additions & 1 deletion src/libslic3r/SupportMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <boost/container/static_vector.hpp>

#include <tbb/parallel_for.h>
#include <tbb/atomic.h>
#include <tbb/spin_mutex.h>
#include <tbb/task_group.h>

Expand Down
12 changes: 6 additions & 6 deletions src/libslic3r/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <tbb/global_control.h>
#include <tbb/parallel_for.h>
#include <tbb/tbb_thread.h>
#include <tbb/task_arena.h>
#include <tbb/task_scheduler_init.h>

#include "Thread.hpp"

Expand Down Expand Up @@ -206,13 +206,13 @@ void name_tbb_thread_pool_threads()
nthreads = 1;
#endif

if (nthreads != nthreads_hw)
new tbb::task_scheduler_init(int(nthreads));
if (nthreads != nthreads_hw)
tbb::global_control(tbb::global_control::max_allowed_parallelism, nthreads);

std::atomic<size_t> nthreads_running(0);
std::condition_variable cv;
std::mutex cv_m;
auto master_thread_id = tbb::this_tbb_thread::get_id();
auto master_thread_id = std::this_thread::get_id();
tbb::parallel_for(
tbb::blocked_range<size_t>(0, nthreads, 1),
[&nthreads_running, nthreads, &master_thread_id, &cv, &cv_m](const tbb::blocked_range<size_t> &range) {
Expand All @@ -226,7 +226,7 @@ void name_tbb_thread_pool_threads()
std::unique_lock<std::mutex> lk(cv_m);
cv.wait(lk, [&nthreads_running, nthreads]{return nthreads_running == nthreads;});
}
auto thread_id = tbb::this_tbb_thread::get_id();
auto thread_id = std::this_thread::get_id();
if (thread_id == master_thread_id) {
// The calling thread runs the 0'th task.
assert(range.begin() == 0);
Expand Down
3 changes: 0 additions & 3 deletions src/libslic3r/pchheader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,9 @@
#include <boost/thread.hpp>
#include <boost/version.hpp>

#include <tbb/atomic.h>
#include <tbb/parallel_for.h>
#include <tbb/spin_mutex.h>
#include <tbb/mutex.h>
#include <tbb/task_group.h>
#include <tbb/task_scheduler_init.h>

#include <Eigen/Dense>
#include <Eigen/Geometry>
Expand Down
6 changes: 2 additions & 4 deletions src/libslic3r/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include <boost/nowide/convert.hpp>
#include <boost/nowide/cstdio.hpp>

#include <tbb/task_scheduler_init.h>
#include <tbb/global_control.h>

#if defined(__linux__) || defined(__GNUC__ )
#include <strings.h>
Expand Down Expand Up @@ -118,9 +118,7 @@ void trace(unsigned int level, const char *message)
void disable_multi_threading()
{
// Disable parallelization so the Shiny profiler works
static tbb::task_scheduler_init *tbb_init = nullptr;
if (tbb_init == nullptr)
tbb_init = new tbb::task_scheduler_init(1);
tbb::global_control(tbb::global_control::max_allowed_parallelism, 1);
}

static std::string g_var_dir;
Expand Down
6 changes: 3 additions & 3 deletions src/slic3r/GUI/BackgroundSlicingProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void BackgroundSlicingProcess::schedule_export(const std::string &path, bool exp
return;

// Guard against entering the export step before changing the export path.
tbb::mutex::scoped_lock lock(m_print->state_mutex());
std::scoped_lock<std::mutex> lock(m_print->state_mutex());
this->invalidate_step(bspsGCodeFinalize);
m_export_path = path;
m_export_path_on_removable_media = export_path_on_removable_media;
Expand All @@ -533,7 +533,7 @@ void BackgroundSlicingProcess::schedule_upload(Slic3r::PrintHostJob upload_job)
return;

// Guard against entering the export step before changing the export path.
tbb::mutex::scoped_lock lock(m_print->state_mutex());
std::scoped_lock<std::mutex> lock(m_print->state_mutex());
this->invalidate_step(bspsGCodeFinalize);
m_export_path.clear();
m_upload_job = std::move(upload_job);
Expand All @@ -546,7 +546,7 @@ void BackgroundSlicingProcess::reset_export()
m_export_path.clear();
m_export_path_on_removable_media = false;
// invalidate_step expects the mutex to be locked.
tbb::mutex::scoped_lock lock(m_print->state_mutex());
std::scoped_lock<std::mutex> lock(m_print->state_mutex());
this->invalidate_step(bspsGCodeFinalize);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/InstanceCheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#if __linux__
#include <boost/thread.hpp>
#include <tbb/mutex.h>
#include <mutex>
#include <condition_variable>
#endif // __linux__

Expand Down
Loading