Path: blob/master/thirdparty/embree/common/tasking/taskschedulertbb.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "../sys/platform.h"6#include "../sys/alloc.h"7#include "../sys/barrier.h"8#include "../sys/thread.h"9#include "../sys/mutex.h"10#include "../sys/condition.h"11#include "../sys/ref.h"1213#if defined(__WIN32__) && !defined(NOMINMAX)14# define NOMINMAX15#endif1617#if defined(__INTEL_LLVM_COMPILER)18// prevents "'__thiscall' calling convention is not supported for this target" warning from TBB19#pragma clang diagnostic push20#pragma clang diagnostic ignored "-Wignored-attributes"21#endif2223// We need to define these to avoid implicit linkage against24// tbb_debug.lib under Windows. When removing these lines debug build25// under Windows fails.26#define __TBB_NO_IMPLICIT_LINKAGE 127#define __TBBMALLOC_NO_IMPLICIT_LINKAGE 128#define TBB_SUPPRESS_DEPRECATED_MESSAGES 129#define TBB_PREVIEW_ISOLATED_TASK_GROUP 130#include "tbb/tbb.h"31#include "tbb/parallel_sort.h"3233#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8)34# define USE_TASK_ARENA 135#else36# define USE_TASK_ARENA 037#endif3839#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION >= 11009) // TBB 2019 Update 940# define TASKING_TBB_USE_TASK_ISOLATION 141#else42# define TASKING_TBB_USE_TASK_ISOLATION 043#endif4445namespace embree46{47struct TaskScheduler48{49/*! initializes the task scheduler */50static void create(size_t numThreads, bool set_affinity, bool start_threads);5152/*! destroys the task scheduler again */53static void destroy();5455/* returns the ID of the current thread */56static __forceinline size_t threadID()57{58return threadIndex();59}6061/* returns the index (0..threadCount-1) of the current thread */62static __forceinline size_t threadIndex()63{64#if TBB_INTERFACE_VERSION >= 910065return tbb::this_task_arena::current_thread_index();66#elif TBB_INTERFACE_VERSION >= 900067return tbb::task_arena::current_thread_index();68#else69return 0;70#endif71}7273/* returns the total number of threads */74static __forceinline size_t threadCount() {75#if TBB_INTERFACE_VERSION >= 910076return tbb::this_task_arena::max_concurrency();77#else78return tbb::task_scheduler_init::default_num_threads();79#endif80}8182};8384};8586#if defined(__INTEL_LLVM_COMPILER)87#pragma clang diagnostic pop88#endif8990