17 #ifndef _TBB_scheduler_common_H 18 #define _TBB_scheduler_common_H 27 #if TBB_USE_ASSERT > 1 35 #define private public 46 #ifndef __TBB_SCHEDULER_MUTEX_TYPE 47 #define __TBB_SCHEDULER_MUTEX_TYPE tbb::spin_mutex 55 #if __TBB_TASK_GROUP_CONTEXT 56 #define __TBB_CONTEXT_ARG1(context) context 57 #define __TBB_CONTEXT_ARG(arg1, context) arg1, context 59 #define __TBB_CONTEXT_ARG1(context) 60 #define __TBB_CONTEXT_ARG(arg1, context) arg1 63 #if __TBB_TASK_ISOLATION 64 #define __TBB_ISOLATION_EXPR(isolation) isolation 65 #define __TBB_ISOLATION_ARG(arg1, isolation) arg1, isolation 67 #define __TBB_ISOLATION_EXPR(isolation) 68 #define __TBB_ISOLATION_ARG(arg1, isolation) arg1 74 #define TBB_TRACE(x) ((void)std::printf x) 76 #define TBB_TRACE(x) ((void)(0)) 79 #if !__TBB_CPU_CTL_ENV_PRESENT 83 #if _MSC_VER && !defined(__INTEL_COMPILER) 87 #pragma warning (disable: 4100 4127 4312 4244 4267 4706) 91 namespace interface7 {
93 class task_arena_base;
98 using namespace interface7::internal;
101 template<
typename SchedulerTraits>
class custom_scheduler;
102 class generic_scheduler;
106 class observer_proxy;
107 class task_scheduler_observer_v3;
109 #if __TBB_TASK_PRIORITY 113 inline intptr_t normalize_priority (
priority_t p ) {
121 inline void assert_priority_valid ( intptr_t
p ) {
125 inline intptr_t& priority (
task& t ) {
126 return t.prefix().context->my_priority;
135 #if __TBB_TASK_GROUP_CONTEXT 146 extern uintptr_t the_context_state_propagation_epoch;
151 extern context_state_propagation_mutex_type the_context_state_propagation_mutex;
167 #if __TBB_PREVIEW_CRITICAL_TASKS 168 es_task_critical = 0x8,
211 template <
typename T>
212 void poison_value ( T& val ) { val = * punned_cast<T*>(&venom); }
215 inline bool is_alive( uintptr_t v ) {
return v != venom; }
223 #if __TBB_RECYCLE_TO_ENQUEUE 224 __TBB_ASSERT( (
unsigned)
task->state()<=(unsigned)task::to_enqueue,
"corrupt task (invalid state)" );
234 #define poison_value(g) ((void)0) 244 #if __TBB_TASK_GROUP_CONTEXT 249 inline bool CancellationInfoPresent (
task& t ) {
250 return t.prefix().context->my_cancellation_requested != 0;
253 #if TBB_USE_CAPTURED_EXCEPTION 254 inline tbb_exception* TbbCurrentException( task_group_context*, tbb_exception* src) {
return src->move(); }
255 inline tbb_exception* TbbCurrentException( task_group_context* c, captured_exception* src) {
257 runtime_warning(
"Exact exception propagation is requested by application but the linked library is built without support for it");
260 #define TbbRethrowException(TbbCapturedException) (TbbCapturedException)->throw_self() 264 #define TbbCurrentException(context, TbbCapturedException) \ 265 context->my_version_and_traits & task_group_context::exact_exception \ 266 ? tbb_exception_ptr::allocate() \ 267 : tbb_exception_ptr::allocate( *(TbbCapturedException) ); 268 #define TbbRethrowException(TbbCapturedException) \ 270 if( governor::rethrow_exception_broken() ) fix_broken_rethrow(); \ 271 (TbbCapturedException)->throw_self(); \ 275 #define TbbRegisterCurrentException(context, TbbCapturedException) \ 276 if ( context->cancel_group_execution() ) { \ 278 context->my_exception = TbbCurrentException( context, TbbCapturedException ); \ 281 #define TbbCatchAll(context) \ 282 catch ( tbb_exception& exc ) { \ 283 TbbRegisterCurrentException( context, &exc ); \ 284 } catch ( std::exception& exc ) { \ 285 TbbRegisterCurrentException( context, captured_exception::allocate(typeid(exc).name(), exc.what()) ); \ 287 TbbRegisterCurrentException( context, captured_exception::allocate("...", "Unidentified exception") );\ 297 #if defined(__TBB_time_stamp) && !__TBB_STEALING_PAUSE 311 }
while ( prev < finish );
313 #ifdef __TBB_STEALING_PAUSE 316 static const long PauseTime = 1500;
318 static const long PauseTime = 80;
350 #if __TBB_PREVIEW_CRITICAL_TASKS 351 unsigned hint_for_critical;
366 statistics_counters *my_counters;
373 void fill_with_canary_pattern (
size_t first,
size_t last ) {
383 my_task_pool_size = byte_size /
sizeof(
task*);
387 fill_with_canary_pattern( 0, my_task_pool_size );
394 if( task_pool_ptr ) {
397 task_pool_ptr = NULL;
398 my_task_pool_size = 0;
403 #if !__TBB_CPU_CTL_ENV_PRESENT 429 __TBB_ASSERT( my_fenv_ptr,
"cpu_ctl_env is not initialized." );
431 return memcmp( (
void*)my_fenv_ptr, (
void*)ctl.
my_fenv_ptr,
sizeof(fenv_t) );
436 fegetenv( my_fenv_ptr );
439 __TBB_ASSERT( my_fenv_ptr,
"cpu_ctl_env is not initialized." );
440 fesetenv( my_fenv_ptr );
__TBB_atomic size_t head
Index of the first ready task in the deque.
static const intptr_t num_priority_levels
const cpu_ctl_env & set_env() const
cpu_ctl_env & operator=(const cpu_ctl_env &src)
static const int priority_stride_v4
auto last(Container &c) -> decltype(begin(c))
free_task_hint
Optimization hint to free_task that enables it omit unnecessary tests and code.
Tag for v1 tasks (i.e. tasks in TBB 1.0 and 2.0)
Bitwise-OR of local_task and small_task.
A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size...
void free_task_pool()
Deallocate task pool that was allocated by means of allocate_task_pool.
void poison_pointer(T *__TBB_atomic &)
const size_t task_prefix_reservation_size
Number of bytes reserved for a task prefix.
task **__TBB_atomic task_pool
bool operator!=(const cpu_ctl_env &ctl) const
auto first(Container &c) -> decltype(begin(c))
#define __TBB_STEALING_PAUSE
#define __TBB_SCHEDULER_MUTEX_TYPE
cpu_ctl_env(const cpu_ctl_env &src)
const size_t task_alignment
Alignment for a task object.
Disable caching for a small task.
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
unsigned hint_for_pop
Hint provided for operations with the container of starvation-resistant tasks.
bool bounded_pause()
Pause for a few times and return false if saturated.
Task is known to be a small task.
generic_scheduler * my_scheduler
Scheduler of the thread attached to the slot.
Task is known to have been allocated by this scheduler.
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
Task is known to be a small task and must not be cached.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Class that implements exponential backoff.
void assert_task_valid(const task *)
void __TBB_Pause(int32_t)
bool ConcurrentWaitsEnabled(task &t)
void allocate_task_pool(size_t n)
#define __TBB_time_stamp()
task **__TBB_atomic task_pool_ptr
Base class for user-defined tasks.
__TBB_atomic size_t tail
Index of the element following the last ready task in the deque.
Work stealing task scheduler.
#define __TBB_ASSERT_EX(predicate, comment)
"Extended" version is useful to suppress warnings if a variable is only used with an assert
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
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.
task to be recycled as continuation
Pads type T to fill out to a multiple of cache line size.
void const char const char int ITT_FORMAT __itt_group_sync p
void reset_extra_state(task *t)
task_extra_state
Definitions for bits in task_prefix::extra_state.
size_t my_task_pool_size
Capacity of the primary task pool (number of elements - pointers to task).
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
__TBB_SCHEDULER_MUTEX_TYPE scheduler_mutex_type
Mutex type for global locks in the scheduler.
Set if the task has been stolen.
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.