21 #ifndef _TBB_scheduler_common_H 22 #define _TBB_scheduler_common_H 31 #if TBB_USE_ASSERT > 1 39 #define private public 50 #ifndef __TBB_SCHEDULER_MUTEX_TYPE 51 #define __TBB_SCHEDULER_MUTEX_TYPE tbb::spin_mutex 59 #if __TBB_TASK_GROUP_CONTEXT 60 #define __TBB_CONTEXT_ARG1(context) context 61 #define __TBB_CONTEXT_ARG(arg1, context) arg1, context 63 #define __TBB_CONTEXT_ARG1(context) 64 #define __TBB_CONTEXT_ARG(arg1, context) arg1 67 #if __TBB_TASK_ISOLATION 68 #define __TBB_ISOLATION_EXPR(isolation) isolation 69 #define __TBB_ISOLATION_ARG(arg1, isolation) arg1, isolation 71 #define __TBB_ISOLATION_EXPR(isolation) 72 #define __TBB_ISOLATION_ARG(arg1, isolation) arg1 78 #define TBB_TRACE(x) ((void)std::printf x) 80 #define TBB_TRACE(x) ((void)(0)) 83 #if !__TBB_CPU_CTL_ENV_PRESENT 87 #if _MSC_VER && !defined(__INTEL_COMPILER) 91 #pragma warning (disable: 4100 4127 4312 4244 4267 4706) 95 namespace interface7 {
97 class task_arena_base;
102 using namespace interface7::internal;
105 template<
typename SchedulerTraits>
class custom_scheduler;
106 class generic_scheduler;
110 class observer_proxy;
111 class task_scheduler_observer_v3;
113 #if __TBB_TASK_PRIORITY 117 inline intptr_t normalize_priority (
priority_t p ) {
125 inline void assert_priority_valid ( intptr_t
p ) {
129 inline intptr_t& priority (
task& t ) {
130 return t.prefix().context->my_priority;
139 #if __TBB_TASK_GROUP_CONTEXT 150 extern uintptr_t the_context_state_propagation_epoch;
155 extern context_state_propagation_mutex_type the_context_state_propagation_mutex;
171 #if __TBB_PREVIEW_CRITICAL_TASKS 172 es_task_critical = 0x8,
215 template <
typename T>
216 void poison_value ( T& val ) { val = * punned_cast<T*>(&venom); }
219 inline bool is_alive( uintptr_t v ) {
return v != venom; }
227 #if __TBB_RECYCLE_TO_ENQUEUE 228 __TBB_ASSERT( (
unsigned)
task->state()<=(unsigned)task::to_enqueue,
"corrupt task (invalid state)" );
238 #define poison_value(g) ((void)0) 248 #if __TBB_TASK_GROUP_CONTEXT 253 inline bool CancellationInfoPresent (
task& t ) {
254 return t.prefix().context->my_cancellation_requested != 0;
257 #if TBB_USE_CAPTURED_EXCEPTION 258 inline tbb_exception* TbbCurrentException( task_group_context*, tbb_exception* src) {
return src->move(); }
259 inline tbb_exception* TbbCurrentException( task_group_context* c, captured_exception* src) {
261 runtime_warning(
"Exact exception propagation is requested by application but the linked library is built without support for it");
264 #define TbbRethrowException(TbbCapturedException) (TbbCapturedException)->throw_self() 268 #define TbbCurrentException(context, TbbCapturedException) \ 269 context->my_version_and_traits & task_group_context::exact_exception \ 270 ? tbb_exception_ptr::allocate() \ 271 : tbb_exception_ptr::allocate( *(TbbCapturedException) ); 272 #define TbbRethrowException(TbbCapturedException) \ 274 if( governor::rethrow_exception_broken() ) fix_broken_rethrow(); \ 275 (TbbCapturedException)->throw_self(); \ 279 #define TbbRegisterCurrentException(context, TbbCapturedException) \ 280 if ( context->cancel_group_execution() ) { \ 282 context->my_exception = TbbCurrentException( context, TbbCapturedException ); \ 285 #define TbbCatchAll(context) \ 286 catch ( tbb_exception& exc ) { \ 287 TbbRegisterCurrentException( context, &exc ); \ 288 } catch ( std::exception& exc ) { \ 289 TbbRegisterCurrentException( context, captured_exception::allocate(typeid(exc).name(), exc.what()) ); \ 291 TbbRegisterCurrentException( context, captured_exception::allocate("...", "Unidentified exception") );\ 301 #if defined(__TBB_time_stamp) && !__TBB_STEALING_PAUSE 315 }
while ( prev < finish );
317 #ifdef __TBB_STEALING_PAUSE 320 static const long PauseTime = 1500;
322 static const long PauseTime = 80;
354 #if __TBB_PREVIEW_CRITICAL_TASKS 355 unsigned hint_for_critical;
370 statistics_counters *my_counters;
377 void fill_with_canary_pattern (
size_t first,
size_t last ) {
387 my_task_pool_size = byte_size /
sizeof(
task*);
391 fill_with_canary_pattern( 0, my_task_pool_size );
398 if( task_pool_ptr ) {
401 task_pool_ptr = NULL;
402 my_task_pool_size = 0;
407 #if !__TBB_CPU_CTL_ENV_PRESENT 433 __TBB_ASSERT( my_fenv_ptr,
"cpu_ctl_env is not initialized." );
435 return memcmp( (
void*)my_fenv_ptr, (
void*)ctl.
my_fenv_ptr,
sizeof(fenv_t) );
440 fegetenv( my_fenv_ptr );
443 __TBB_ASSERT( my_fenv_ptr,
"cpu_ctl_env is not initialized." );
444 fesetenv( my_fenv_ptr );
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
#define __TBB_time_stamp()
A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size...
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
Tag for v3 tasks (i.e. tasks in TBB 2.1-2.2)
void fill_with_canary_pattern(size_t, size_t)
Set if ref_count might be changed by another thread. Used for debugging.
Disable caching for a small task.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Task is known to have been allocated by this scheduler.
task **__TBB_atomic task_pool_ptr
const cpu_ctl_env & set_env() const
auto first(Container &c) -> decltype(begin(c))
Task is known to be a small task and must not be cached.
Task is known to be a small task.
bool bounded_pause()
Pause for a few times and return false if saturated.
void allocate_task_pool(size_t n)
void reset_extra_state(task *t)
cpu_ctl_env & operator=(const cpu_ctl_env &src)
__TBB_atomic size_t head
Index of the first ready task in the deque.
Base class for user-defined tasks.
Work stealing task scheduler.
Set if the task has been stolen.
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
#define __TBB_SCHEDULER_MUTEX_TYPE
generic_scheduler * my_scheduler
Scheduler of the thread attached to the slot.
void const char const char int ITT_FORMAT __itt_group_sync p
free_task_hint
Optimization hint to free_task that enables it omit unnecessary tests and code.
task_extra_state
Definitions for bits in task_prefix::extra_state.
auto last(Container &c) -> decltype(begin(c))
task **__TBB_atomic task_pool
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task * task
__TBB_atomic size_t tail
Index of the element following the last ready task in the deque.
static const intptr_t num_priority_levels
__TBB_SCHEDULER_MUTEX_TYPE scheduler_mutex_type
Mutex type for global locks in the scheduler.
bool operator!=(const cpu_ctl_env &ctl) const
static const int priority_stride_v4
task to be recycled as continuation
void poison_pointer(T *__TBB_atomic &)
Class that implements exponential backoff.
const size_t task_alignment
Alignment for a task object.
#define __TBB_STEALING_PAUSE
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
void free_task_pool()
Deallocate task pool that was allocated by means of allocate_task_pool.
size_t my_task_pool_size
Capacity of the primary task pool (number of elements - pointers to task).
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
void assert_task_valid(const task *)
const size_t task_prefix_reservation_size
Number of bytes reserved for a task prefix.
bool ConcurrentWaitsEnabled(task &t)
Tag for v1 tasks (i.e. tasks in TBB 1.0 and 2.0)
Bitwise-OR of local_task and small_task.
cpu_ctl_env(const cpu_ctl_env &src)
unsigned hint_for_pop
Hint provided for operations with the container of starvation-resistant tasks.
void __TBB_Pause(int32_t)
Pads type T to fill out to a multiple of cache line size.