Listing the "Blender Foundation" as copyright holder implied the Blender Foundation holds copyright to files which may include work from many developers. While keeping copyright on headers makes sense for isolated libraries, Blender's own code may be refactored or moved between files in a way that makes the per file copyright holders less meaningful. Copyright references to the "Blender Foundation" have been replaced with "Blender Authors", with the exception of `./extern/` since these this contains libraries which are more isolated, any changed to license headers there can be handled on a case-by-case basis. Some directories in `./intern/` have also been excluded: - `./intern/cycles/` it's own `AUTHORS` file is planned. - `./intern/opensubdiv/`. An "AUTHORS" file has been added, using the chromium projects authors file as a template. Design task: #110784 Ref !110783.
79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup bli
|
|
*
|
|
* Task scheduler initialization.
|
|
*/
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "BLI_lazy_threading.hh"
|
|
#include "BLI_task.h"
|
|
#include "BLI_threads.h"
|
|
|
|
#ifdef WITH_TBB
|
|
/* Need to include at least one header to get the version define. */
|
|
# include <tbb/blocked_range.h>
|
|
# include <tbb/task_arena.h>
|
|
# if TBB_INTERFACE_VERSION_MAJOR >= 10
|
|
# include <tbb/global_control.h>
|
|
# define WITH_TBB_GLOBAL_CONTROL
|
|
# endif
|
|
#endif
|
|
|
|
/* Task Scheduler */
|
|
|
|
static int task_scheduler_num_threads = 1;
|
|
#ifdef WITH_TBB_GLOBAL_CONTROL
|
|
static tbb::global_control *task_scheduler_global_control = nullptr;
|
|
#endif
|
|
|
|
void BLI_task_scheduler_init()
|
|
{
|
|
#ifdef WITH_TBB_GLOBAL_CONTROL
|
|
const int threads_override_num = BLI_system_num_threads_override_get();
|
|
|
|
if (threads_override_num > 0) {
|
|
/* Override number of threads. This settings is used within the lifetime
|
|
* of tbb::global_control, so we allocate it on the heap. */
|
|
task_scheduler_global_control = MEM_new<tbb::global_control>(
|
|
__func__, tbb::global_control::max_allowed_parallelism, threads_override_num);
|
|
task_scheduler_num_threads = threads_override_num;
|
|
}
|
|
else {
|
|
/* Let TBB choose the number of threads. For (legacy) code that calls
|
|
* BLI_task_scheduler_num_threads() we provide the system thread count.
|
|
* Ideally such code should be rewritten not to use the number of threads
|
|
* at all. */
|
|
task_scheduler_num_threads = BLI_system_thread_count();
|
|
}
|
|
#else
|
|
task_scheduler_num_threads = BLI_system_thread_count();
|
|
#endif
|
|
}
|
|
|
|
void BLI_task_scheduler_exit()
|
|
{
|
|
#ifdef WITH_TBB_GLOBAL_CONTROL
|
|
MEM_delete(task_scheduler_global_control);
|
|
#endif
|
|
}
|
|
|
|
int BLI_task_scheduler_num_threads()
|
|
{
|
|
return task_scheduler_num_threads;
|
|
}
|
|
|
|
void BLI_task_isolate(void (*func)(void *userdata), void *userdata)
|
|
{
|
|
#ifdef WITH_TBB
|
|
blender::lazy_threading::ReceiverIsolation isolation;
|
|
tbb::this_task_arena::isolate([&] { func(userdata); });
|
|
#else
|
|
func(userdata);
|
|
#endif
|
|
}
|