mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-18 04:08:02 -06:00
drop deprecated TBB components (#6590)
Quite some time ago, many of the TBB components were deprecated in favor of their near-equivalents in the STL or, in the case of task_scheduler_init, were broken up and reconstituted under a less ad-hoc logic. Every time a header file marked deprecated gets included, a rather loud warning is emitted, which leads to a complete TBB's domination over the stderr stream during build time, making it harder to notice _legitimate_ warnings. Instead of merely muting the output with TBB_SUPPRESS_DEPRECATED_MESSAGES, perform a genuine migration away from the deprecated components with the added benefit of achieving a source compatibility with oneTBB, the successor to TBB which has dropped the deprecated API for good. What got replaced for what? | Deprecated | Replacement | | ------------------------------------- | --------------------------------------------- | | `tbb::atomic` | `std::atomic` | | `tbb::mutex` | `std::mutex` | | `tbb::mutex::scoped_lock` | `std::scoped_lock<std::mutex>` | | `tbb::mutex::scoped_lock` (empty) | `std::unique_lock<std::mutex>` (deferred) | | `tbb::task_scheduler_init` | `tbb::global_control` | | `tbb::this_thread` | `std::this_thread` | Signed-off-by: Roman Beranek <roman.beranek@prusa3d.com>
This commit is contained in:
parent
7a7108b2ad
commit
e13535f822
18 changed files with 80 additions and 95 deletions
|
@ -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"
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue