Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/common/tasking/taskschedulertbb.h
9912 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "../sys/platform.h"
7
#include "../sys/alloc.h"
8
#include "../sys/barrier.h"
9
#include "../sys/thread.h"
10
#include "../sys/mutex.h"
11
#include "../sys/condition.h"
12
#include "../sys/ref.h"
13
14
#if defined(__WIN32__) && !defined(NOMINMAX)
15
# define NOMINMAX
16
#endif
17
18
#if defined(__INTEL_LLVM_COMPILER)
19
// prevents "'__thiscall' calling convention is not supported for this target" warning from TBB
20
#pragma clang diagnostic push
21
#pragma clang diagnostic ignored "-Wignored-attributes"
22
#endif
23
24
// We need to define these to avoid implicit linkage against
25
// tbb_debug.lib under Windows. When removing these lines debug build
26
// under Windows fails.
27
#define __TBB_NO_IMPLICIT_LINKAGE 1
28
#define __TBBMALLOC_NO_IMPLICIT_LINKAGE 1
29
#define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
30
#define TBB_PREVIEW_ISOLATED_TASK_GROUP 1
31
#include "tbb/tbb.h"
32
#include "tbb/parallel_sort.h"
33
34
#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION_MAJOR >= 8)
35
# define USE_TASK_ARENA 1
36
#else
37
# define USE_TASK_ARENA 0
38
#endif
39
40
#if defined(TASKING_TBB) && (TBB_INTERFACE_VERSION >= 11009) // TBB 2019 Update 9
41
# define TASKING_TBB_USE_TASK_ISOLATION 1
42
#else
43
# define TASKING_TBB_USE_TASK_ISOLATION 0
44
#endif
45
46
namespace embree
47
{
48
struct TaskScheduler
49
{
50
/*! initializes the task scheduler */
51
static void create(size_t numThreads, bool set_affinity, bool start_threads);
52
53
/*! destroys the task scheduler again */
54
static void destroy();
55
56
/* returns the ID of the current thread */
57
static __forceinline size_t threadID()
58
{
59
return threadIndex();
60
}
61
62
/* returns the index (0..threadCount-1) of the current thread */
63
static __forceinline size_t threadIndex()
64
{
65
#if TBB_INTERFACE_VERSION >= 9100
66
return tbb::this_task_arena::current_thread_index();
67
#elif TBB_INTERFACE_VERSION >= 9000
68
return tbb::task_arena::current_thread_index();
69
#else
70
return 0;
71
#endif
72
}
73
74
/* returns the total number of threads */
75
static __forceinline size_t threadCount() {
76
#if TBB_INTERFACE_VERSION >= 9100
77
return tbb::this_task_arena::max_concurrency();
78
#else
79
return tbb::task_scheduler_init::default_num_threads();
80
#endif
81
}
82
83
};
84
85
};
86
87
#if defined(__INTEL_LLVM_COMPILER)
88
#pragma clang diagnostic pop
89
#endif
90