20 #define __TBB_task_H_include_area 34 class task_group_context;
38 #if _MSC_VER || (__GNUC__==3 && __GNUC_MINOR__<3) 39 #define __TBB_TASK_BASE_ACCESS public 41 #define __TBB_TASK_BASE_ACCESS private 61 namespace interface5 {
74 static void spawn(
task& t );
108 virtual void spawn_root_and_wait(
task& first,
task*& next ) = 0;
115 virtual void enqueue(
task& t,
void* reserved ) = 0;
122 #if __TBB_PREVIEW_RESUMABLE_TASKS 130 #if __TBB_TASK_ISOLATION 136 #if __TBB_TASK_GROUP_CONTEXT 171 #if __TBB_PREVIEW_CRITICAL_TASKS 202 #if __TBB_PREVIEW_CRITICAL_TASKS 207 #if __TBB_TASK_ISOLATION 208 isolation_tag isolation;
211 intptr_t reserved_space_for_task_isolation_tag;
214 #if __TBB_TASK_GROUP_CONTEXT 230 #if __TBB_TASK_PRIORITY || __TBB_PREVIEW_RESUMABLE_TASKS 238 #if __TBB_TASK_PRIORITY 244 #if __TBB_PREVIEW_RESUMABLE_TASKS 248 #if __TBB_TASK_PRIORITY || __TBB_PREVIEW_RESUMABLE_TASKS 295 #if __TBB_TASK_GROUP_CONTEXT 297 #if __TBB_TASK_PRIORITY 300 #if __TBB_PREVIEW_CRITICAL_TASKS 314 #if TBB_USE_CAPTURED_EXCEPTION 353 #if TBB_USE_CAPTURED_EXCEPTION 361 version_mask = 0xFFFF,
362 traits_mask = 0xFFFFul << traits_offset
372 exact_exception = 0x0001ul << traits_offset,
374 fp_settings = 0x0002ul << traits_offset,
376 concurrent_wait = 0x0004ul << traits_offset,
377 #if TBB_USE_CAPTURED_EXCEPTION 380 default_traits = exact_exception
386 may_have_children = 1,
446 #if __TBB_TASK_PRIORITY 447 intptr_t my_priority;
457 #if __TBB_TASK_PRIORITY 494 uintptr_t t = default_traits )
495 : my_kind(relation_with_parent)
496 , my_version_and_traits(3 | t)
505 , my_version_and_traits(3 | default_traits)
558 #if __TBB_TASK_PRIORITY 567 uintptr_t
traits()
const {
return my_version_and_traits & traits_mask; }
584 template <
typename T>
614 task() {prefix().extra_state=1;}
621 virtual task* execute() = 0;
637 #if __TBB_RECYCLE_TO_ENQUEUE 641 #if __TBB_PREVIEW_RESUMABLE_TASKS 656 #if __TBB_TASK_GROUP_CONTEXT 675 using task_base::allocate_additional_child_of;
677 #if __TBB_DEPRECATED_TASK_INTERFACE 685 using task_base::destroy;
701 __TBB_ASSERT( prefix().state==executing,
"execute not running?" );
702 prefix().state = allocated;
709 __TBB_ASSERT( prefix().state==executing,
"execute not running?" );
710 prefix().state = recycle;
716 __TBB_ASSERT( prefix().state==executing||prefix().state==allocated,
"execute not running, or already recycled" );
717 __TBB_ASSERT( prefix().ref_count==0,
"no child tasks allowed when recycled as a child" );
723 #if __TBB_TASK_GROUP_CONTEXT 731 __TBB_ASSERT( prefix().state==executing,
"execute not running, or already recycled" );
732 __TBB_ASSERT( prefix().ref_count==0,
"no child tasks allowed when recycled for reexecution" );
733 prefix().state = reexecute;
736 #if __TBB_RECYCLE_TO_ENQUEUE 739 void recycle_to_enqueue() {
740 __TBB_ASSERT( prefix().state==executing,
"execute not running, or already recycled" );
741 prefix().state = to_enqueue;
751 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT 752 internal_set_ref_count(count);
754 prefix().ref_count =
count;
769 __TBB_ASSERT( k>=0,
"task's reference count underflowed" );
778 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT 779 return int(internal_decrement_ref_count());
786 using task_base::spawn;
790 prefix().owner->wait_for_all( *
this, &child );
804 static void spawn_root_and_wait(
task_list& root_list );
809 prefix().owner->wait_for_all( *
this, NULL );
813 #if __TBB_TASK_PRIORITY 829 #if __TBB_TASK_PRIORITY 832 #if __TBB_PREVIEW_CRITICAL_TASKS 844 #if __TBB_TASK_PRIORITY 858 #if __TBB_TASK_GROUP_CONTEXT 864 #if __TBB_TASK_GROUP_CONTEXT 875 return (prefix().extra_state & 0x80)!=0;
881 return (prefix().extra_state & 0x10)!=0;
884 #if __TBB_PREVIEW_RESUMABLE_TASKS 885 typedef void* suspend_point;
889 template <
typename F>
890 static void suspend(F f);
893 static void resume(suspend_point tag);
906 #if __TBB_PREVIEW_RESUMABLE_TASKS 911 __TBB_ASSERT( ref_count_==
int(ref_count_),
"integer overflow error");
913 #if __TBB_PREVIEW_RESUMABLE_TASKS 914 return int(prefix().ref_count & ~internal::abandon_flag);
916 return int(prefix().ref_count);
935 affinity_id
affinity()
const {
return prefix().affinity;}
944 #if __TBB_TASK_GROUP_CONTEXT 963 bool is_cancelled ()
const {
return prefix().context->is_group_execution_cancelled(); }
965 bool is_cancelled ()
const {
return false; }
968 #if __TBB_TASK_PRIORITY 982 #if __TBB_TASK_GROUP_CONTEXT 994 #if __TBB_PREVIEW_CRITICAL_TASKS 1000 #if __TBB_PREVIEW_CRITICAL_TASKS 1007 #if __TBB_PREVIEW_RESUMABLE_TASKS 1009 template <
typename F>
1010 static void suspend_callback(
void* user_callback, task::suspend_point tag) {
1012 F user_callback_copy = *
static_cast<F*
>(user_callback);
1013 user_callback_copy(tag);
1020 template <
typename F>
1021 inline void task::suspend(F f) {
1022 internal::internal_suspend((
void*)internal::suspend_callback<F>, &f);
1024 inline void task::resume(suspend_point tag) {
1025 internal::internal_resume(tag);
1039 template<
typename F>
1041 #if __TBB_ALLOW_MUTABLE_FUNCTORS 1053 #if __TBB_CPP11_RVALUE_REF_PRESENT 1099 __TBB_ASSERT( !empty(),
"attempt to pop item from empty task_list" );
1100 task* result =
first;
1102 if( !first ) next_ptr = &
first;
1119 t->prefix().owner->spawn( *t, *list.
next_ptr );
1126 t->prefix().owner->spawn_root_and_wait( *t, *root_list.
next_ptr );
1141 #if __TBB_TASK_GROUP_CONTEXT 1143 return &
p.allocate(bytes);
1147 p.free( *static_cast<tbb::task*>(task) );
1152 return &
p.allocate(bytes);
1156 p.free( *static_cast<tbb::task*>(task) );
1160 return &
p.allocate(bytes);
1164 p.free( *static_cast<tbb::task*>(task) );
1168 return &
p.allocate(bytes);
1172 p.free( *static_cast<tbb::task*>(task) );
1176 #undef __TBB_task_H_include_area static const int priority_stride_v4
task_group_context * context
Shared context that is used to communicate asynchronous state changes.
tbb::task * parent
The task whose reference count includes me.
state_type
Enumeration of task states that the scheduler considers.
internal::cpu_ctl_env_space my_cpu_ctl_env
Space for platform-specific FPU settings.
Base class for types that should not be assigned.
uintptr_t traits() const
Returns the context's trait.
tbb::task * next
"next" field for list of task
function_task(const F &f)
exception_container_type * my_exception
Pointer to the container storing exception being propagated across this task group.
internal::affinity_id affinity_id
An id as used for specifying affinity.
task()
Default constructor.
void recycle_as_continuation()
Change this to be a continuation of its former self.
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 __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
void recycle_to_reexecute()
Schedule this for reexecution after current execute() returns.
task_group_context * group()
Pointer to the task group descriptor.
internal::string_index my_name
Description of algorithm for scheduler based instrumentation.
uintptr_t my_version_and_traits
Version for run-time checks and behavioral traits of the context.
__TBB_atomic reference_count ref_count
Reference count used for synchronization.
virtual void spawn_root_and_wait(task &first, task *&next)=0
For internal use only.
internal::generic_scheduler * my_owner
Scheduler instance that registered this context in its thread specific list.
void call_itt_notify(notify_type, void *)
void recycle_as_safe_continuation()
Recommended to use, safe variant of recycle_as_continuation.
task_group_context(kind_type relation_with_parent=bound, uintptr_t t=default_traits)
Default & binding constructor.
static void enqueue(task &t)
Enqueue task for starvation-resistant execution.
Base class for types that should not be copied or assigned.
bool is_enqueued_task() const
True if the task was enqueued.
bool is_cancelled() const
Returns true if the context has received cancellation request.
task is running, and will be destroyed after method execute() completes.
void set_ref_count(int count)
Set reference count.
__TBB_DEPRECATED priority_t group_priority() const
Retrieves current priority of the task group this task belongs to.
int decrement_ref_count()
Atomically decrement reference count and returns its new value.
static void __TBB_EXPORTED_FUNC free(task &)
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 __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t count
state_type state() const
Current execution state.
Exception container that preserves the exact copy of the original exception.
static task &__TBB_EXPORTED_FUNC allocate(size_t size)
virtual ~task()
Destructor.
void wait_for_all()
Wait for reference count to become one, and set reference count to zero.
#define __TBB_TASK_BASE_ACCESS
task &__TBB_EXPORTED_METHOD allocate(size_t size) const
task is in ready pool, or is going to be put there, or was just taken off.
auto first(Container &c) -> decltype(begin(c))
unsigned char state
A task::state_type, stored as a byte for compactness.
task_group_context(internal::string_index name)
__TBB_atomic kind_type my_kind
Flavor of this context: bound or isolated.
internal::tbb_exception_ptr exception_container_type
void push_back(task &task)
Push task onto back of list.
void make_critical(task &t)
bool cancel_group_execution()
Initiates cancellation of all tasks in this cancellation group and its subordinate groups...
static const int priority_critical
uintptr_t my_cancellation_requested
Specifies whether cancellation was requested for this task group.
tbb::task & task()
The task corresponding to this task_prefix.
internal::allocate_continuation_proxy & allocate_continuation()
Returns proxy for overloaded new that allocates a continuation task of *this.
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
version_traits_word_layout
struct ___itt_caller * __itt_caller
scheduler * owner
Obsolete. The scheduler that owns the task.
void move(tbb_thread &t1, tbb_thread &t2)
task_group_context * context()
This method is deprecated and will be removed in the future.
task_list()
Construct empty list.
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads...
Memory prefix to a task object.
internal::context_list_node_t my_node
Used to form the thread specific list of contexts without additional memory allocation.
bool is_stolen_task() const
True if task was stolen from the task pool of another thread.
intptr_t isolation_tag
A tag for task isolation.
task * self
No longer used, but retained for binary layout compatibility. Always NULL.
#define __TBB_EXPORTED_FUNC
uintptr_t my_state
Internal state (combination of state flags, currently only may_have_children).
allocate_additional_child_of_proxy(task &parent_)
__itt_caller itt_caller
Used to set and maintain stack stitching point for Intel Performance Tools.
intptr_t reference_count
A reference count.
allocate_root_with_context_proxy(task_group_context &ctx)
void set_parent(task *p)
sets parent task pointer to specified value
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
task that does nothing. Useful for synchronization.
uintptr_t _my_kind_aligner
int depth
Obsolete. Used to be scheduling depth before TBB 2.2.
void increment_ref_count()
Atomically increment reference count.
static void spawn(task &t)
Schedule task for execution when a worker becomes available.
void clear()
Clear the list.
int ref_count() const
The internal reference count.
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
static tbb::internal::allocate_additional_child_of_proxy allocate_additional_child_of(task &t)
Like allocate_child, except that task's parent becomes "t", not this.
unsigned char extra_state
Miscellaneous state that is not directly visible to users, stored as a byte for compactness.
affinity_id affinity() const
Current affinity of this task.
unsigned short affinity_id
An id as used for specifying affinity.
task * execute() __TBB_override
Should be overridden by derived classes.
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
scheduler * origin
The scheduler that allocated the task, or NULL if the task is big.
virtual void spawn(task &first, task *&next)=0
For internal use only.
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 __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id id
bool empty() const
True if list is empty; false otherwise.
task object is on free list, or is going to be put there, or was just taken off.
static void spawn_root_and_wait(task &root)
Spawn task allocated by allocate_root, wait for it to complete, and deallocate it.
#define __TBB_FetchAndDecrementWrelease(P)
void set_affinity(affinity_id id)
Set affinity for this task.
void __TBB_EXPORTED_METHOD free(task &) const
#define __TBB_EXPORTED_METHOD
void recycle_as_child_of(task &new_parent)
Change this to be a child of new_parent.
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Used to form groups of tasks.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
int add_ref_count(int count)
Atomically adds to reference count and returns its new value.
Class delimiting the scope of task scheduler activity.
task * next_offloaded
Pointer to the next offloaded lower priority task.
#define __TBB_FetchAndIncrementWacquire(P)
task_group_context * my_parent
Pointer to the context of the parent cancellation group. NULL for isolated contexts.
Base class for methods that became static in TBB 3.0.
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
void spawn_and_wait_for_all(task &child)
Similar to spawn followed by wait_for_all, but more efficient.
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 size
void const char const char int ITT_FORMAT __itt_group_sync p
task * execute() __TBB_override
Should be overridden by derived classes.
context_list_node_t * my_prev
internal::allocate_child_proxy & allocate_child()
Returns proxy for overloaded new that allocates a child task of *this.
const isolation_tag no_isolation
task * parent() const
task on whose behalf this task is working, or NULL if this is a root.
task_group_context & my_context
Base class for user-defined tasks.
~task_list()
Destroys the list, but does not destroy the task objects.
Work stealing task scheduler.
virtual void enqueue(task &t, void *reserved)=0
For internal use only.
task object is freshly allocated or recycled.
bool is_critical(task &t)