Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
task.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2018 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 #ifndef __TBB_task_H
22 #define __TBB_task_H
23 
24 #include "tbb_stddef.h"
25 #include "tbb_machine.h"
26 #include "tbb_profiling.h"
27 #include <climits>
28 
29 typedef struct ___itt_caller *__itt_caller;
30 
31 namespace tbb {
32 
33 class task;
34 class task_list;
35 class task_group_context;
36 
37 // MSVC does not allow taking the address of a member that was defined
38 // privately in task_base and made public in class task via a using declaration.
39 #if _MSC_VER || (__GNUC__==3 && __GNUC_MINOR__<3)
40 #define __TBB_TASK_BASE_ACCESS public
41 #else
42 #define __TBB_TASK_BASE_ACCESS private
43 #endif
44 
45 namespace internal { //< @cond INTERNAL
46 
49  task* self;
51  public:
52  explicit allocate_additional_child_of_proxy( task& parent_ ) : self(NULL), parent(parent_) {}
53  task& __TBB_EXPORTED_METHOD allocate( size_t size ) const;
54  void __TBB_EXPORTED_METHOD free( task& ) const;
55  };
56 
57  struct cpu_ctl_env_space { int space[sizeof(internal::uint64_t)/sizeof(int)]; };
58 } //< namespace internal @endcond
59 
60 namespace interface5 {
61  namespace internal {
63 
70  friend class tbb::task;
71 
73  static void spawn( task& t );
74 
76  static void spawn( task_list& list );
77 
79 
83  }
84 
86 
90  static void __TBB_EXPORTED_FUNC destroy( task& victim );
91  };
92  } // internal
93 } // interface5
94 
96 namespace internal {
97 
98  class scheduler: no_copy {
99  public:
101  virtual void spawn( task& first, task*& next ) = 0;
102 
104  virtual void wait_for_all( task& parent, task* child ) = 0;
105 
107  virtual void spawn_root_and_wait( task& first, task*& next ) = 0;
108 
110  // Have to have it just to shut up overzealous compilation warnings
111  virtual ~scheduler() = 0;
112 
114  virtual void enqueue( task& t, void* reserved ) = 0;
115  };
116 
118 
119  typedef intptr_t reference_count;
120 
122  typedef unsigned short affinity_id;
123 
124 #if __TBB_TASK_ISOLATION
125  typedef intptr_t isolation_tag;
128 #endif /* __TBB_TASK_ISOLATION */
129 
130 #if __TBB_TASK_GROUP_CONTEXT
131  class generic_scheduler;
132 
135  *my_next;
136  };
137 
140  public:
142  task& __TBB_EXPORTED_METHOD allocate( size_t size ) const;
143  void __TBB_EXPORTED_METHOD free( task& ) const;
144  };
145 #endif /* __TBB_TASK_GROUP_CONTEXT */
146 
148  public:
149  static task& __TBB_EXPORTED_FUNC allocate( size_t size );
150  static void __TBB_EXPORTED_FUNC free( task& );
151  };
152 
154  public:
155  task& __TBB_EXPORTED_METHOD allocate( size_t size ) const;
156  void __TBB_EXPORTED_METHOD free( task& ) const;
157  };
158 
160  public:
161  task& __TBB_EXPORTED_METHOD allocate( size_t size ) const;
162  void __TBB_EXPORTED_METHOD free( task& ) const;
163  };
164 
166 
180  class task_prefix {
181  private:
182  friend class tbb::task;
184  friend class tbb::task_list;
185  friend class internal::scheduler;
190 
191 #if __TBB_TASK_ISOLATION
194 #else
195  intptr_t reserved_space_for_task_isolation_tag;
196 #endif /* __TBB_TASK_ISOLATION */
197 
198 #if __TBB_TASK_GROUP_CONTEXT
199 
204 #endif /* __TBB_TASK_GROUP_CONTEXT */
205 
207 
213 
214 #if __TBB_TASK_PRIORITY
215  union {
216 #endif /* __TBB_TASK_PRIORITY */
217 
221 
222 #if __TBB_TASK_PRIORITY
223 
226  };
227 #endif /* __TBB_TASK_PRIORITY */
228 
230 
234 
236 
241 
243 
245  int depth;
246 
248 
249  unsigned char state;
250 
252 
258  unsigned char extra_state;
259 
261 
264 
266  tbb::task& task() {return *reinterpret_cast<tbb::task*>(this+1);}
267  };
268 
269 } // namespace internal
271 
272 #if __TBB_TASK_GROUP_CONTEXT
273 
274 #if __TBB_TASK_PRIORITY
275 namespace internal {
276  static const int priority_stride_v4 = INT_MAX / 4;
277 }
278 
283 };
284 
285 #endif /* __TBB_TASK_PRIORITY */
286 
287 #if TBB_USE_CAPTURED_EXCEPTION
288  class tbb_exception;
289 #else
290  namespace internal {
291  class tbb_exception_ptr;
292  }
293 #endif /* !TBB_USE_CAPTURED_EXCEPTION */
294 
295 class task_scheduler_init;
296 namespace interface7 { class task_arena; }
297 
299 
319 class task_group_context : internal::no_copy {
320 private:
322  friend class task_scheduler_init;
324 
325 #if TBB_USE_CAPTURED_EXCEPTION
327 #else
328  typedef internal::tbb_exception_ptr exception_container_type;
329 #endif
330 
333  version_mask = 0xFFFF,
335  };
336 
337 public:
338  enum kind_type {
341  };
342 
343  enum traits_type {
345 #if __TBB_FP_CONTEXT
346  fp_settings = 0x0002ul << traits_offset,
347 #endif
349 #if TBB_USE_CAPTURED_EXCEPTION
350  default_traits = 0
351 #else
353 #endif /* !TBB_USE_CAPTURED_EXCEPTION */
354  };
355 
356 private:
357  enum state {
359  // the following enumerations must be the last, new 2^x values must go above
361  };
362 
363  union {
365  // TODO: describe asynchronous use, and whether any memory semantics are needed
367  uintptr_t _my_kind_aligner;
368  };
369 
372 
374 
376  internal::context_list_node_t my_node;
377 
380 
382 
386  - 2 * sizeof(uintptr_t)- sizeof(void*) - sizeof(internal::context_list_node_t)
387  - sizeof(__itt_caller)
388 #if __TBB_FP_CONTEXT
389  - sizeof(internal::cpu_ctl_env_space)
390 #endif
391  ];
392 
393 #if __TBB_FP_CONTEXT
394 
397  internal::cpu_ctl_env_space my_cpu_ctl_env;
398 #endif
399 
402 
404 
408 
411 
414 
416  uintptr_t my_state;
417 
418 #if __TBB_TASK_PRIORITY
419  intptr_t my_priority;
421 #endif /* __TBB_TASK_PRIORITY */
422 
425 
427 
428  char _trailing_padding[internal::NFS_MaxLineSize - 2 * sizeof(uintptr_t) - 2 * sizeof(void*)
429 #if __TBB_TASK_PRIORITY
430  - sizeof(intptr_t)
431 #endif /* __TBB_TASK_PRIORITY */
432  - sizeof(internal::string_index)
433  ];
434 
435 public:
437 
465  task_group_context ( kind_type relation_with_parent = bound,
466  uintptr_t t = default_traits )
467  : my_kind(relation_with_parent)
468  , my_version_and_traits(3 | t)
469  , my_name(internal::CUSTOM_CTX)
470  {
471  init();
472  }
473 
474  // Custom constructor for instrumentation of tbb algorithm
476  : my_kind(bound)
478  , my_name(name)
479  {
480  init();
481  }
482 
483  // Do not introduce standalone unbind method since it will break state propagation assumptions
485 
487 
495 
497 
505 
508 
510 
517 
518 #if __TBB_FP_CONTEXT
519 
528 #endif
529 
530 #if __TBB_TASK_PRIORITY
531  void set_priority ( priority_t );
533 
535  priority_t priority () const;
536 #endif /* __TBB_TASK_PRIORITY */
537 
539  uintptr_t traits() const { return my_version_and_traits & traits_mask; }
540 
541 protected:
543 
544  void __TBB_EXPORTED_METHOD init ();
545 
546 private:
547  friend class task;
549 
553  static const kind_type dying = kind_type(detached+1);
554 
556  template <typename T>
557  void propagate_task_group_state ( T task_group_context::*mptr_state, task_group_context& src, T new_state );
558 
560  void bind_to ( internal::generic_scheduler *local_sched );
561 
563  void register_with ( internal::generic_scheduler *local_sched );
564 
565 #if __TBB_FP_CONTEXT
566  // TODO: Consider adding #else stub in order to omit #if sections in other code
568  void copy_fp_settings( const task_group_context &src );
569 #endif /* __TBB_FP_CONTEXT */
570 }; // class task_group_context
571 
572 #endif /* __TBB_TASK_GROUP_CONTEXT */
573 
575 
577 
580 
583 
584 protected:
586  task() {prefix().extra_state=1;}
587 
588 public:
590  virtual ~task() {}
591 
593  virtual task* execute() = 0;
594 
596  enum state_type {
609 #if __TBB_RECYCLE_TO_ENQUEUE
610  ,to_enqueue
612 #endif
613  };
614 
615  //------------------------------------------------------------------------
616  // Allocating tasks
617  //------------------------------------------------------------------------
618 
622  }
623 
624 #if __TBB_TASK_GROUP_CONTEXT
625  static internal::allocate_root_with_context_proxy allocate_root( task_group_context& ctx ) {
627  return internal::allocate_root_with_context_proxy(ctx);
628  }
629 #endif /* __TBB_TASK_GROUP_CONTEXT */
630 
632 
634  return *reinterpret_cast<internal::allocate_continuation_proxy*>(this);
635  }
636 
639  return *reinterpret_cast<internal::allocate_child_proxy*>(this);
640  }
641 
643  using task_base::allocate_additional_child_of;
644 
645 #if __TBB_DEPRECATED_TASK_INTERFACE
646 
651  void __TBB_EXPORTED_METHOD destroy( task& t );
652 #else /* !__TBB_DEPRECATED_TASK_INTERFACE */
653  using task_base::destroy;
655 #endif /* !__TBB_DEPRECATED_TASK_INTERFACE */
656 
657  //------------------------------------------------------------------------
658  // Recycling of tasks
659  //------------------------------------------------------------------------
660 
662 
669  __TBB_ASSERT( prefix().state==executing, "execute not running?" );
670  prefix().state = allocated;
671  }
672 
674 
677  __TBB_ASSERT( prefix().state==executing, "execute not running?" );
678  prefix().state = recycle;
679  }
680 
682  void recycle_as_child_of( task& new_parent ) {
683  internal::task_prefix& p = prefix();
684  __TBB_ASSERT( prefix().state==executing||prefix().state==allocated, "execute not running, or already recycled" );
685  __TBB_ASSERT( prefix().ref_count==0, "no child tasks allowed when recycled as a child" );
686  __TBB_ASSERT( p.parent==NULL, "parent must be null" );
687  __TBB_ASSERT( new_parent.prefix().state<=recycle, "corrupt parent's state" );
688  __TBB_ASSERT( new_parent.prefix().state!=freed, "parent already freed" );
689  p.state = allocated;
690  p.parent = &new_parent;
691 #if __TBB_TASK_GROUP_CONTEXT
692  p.context = new_parent.prefix().context;
693 #endif /* __TBB_TASK_GROUP_CONTEXT */
694  }
695 
697 
699  __TBB_ASSERT( prefix().state==executing, "execute not running, or already recycled" );
700  __TBB_ASSERT( prefix().ref_count==0, "no child tasks allowed when recycled for reexecution" );
701  prefix().state = reexecute;
702  }
703 
704 #if __TBB_RECYCLE_TO_ENQUEUE
705 
707  void recycle_to_enqueue() {
708  __TBB_ASSERT( prefix().state==executing, "execute not running, or already recycled" );
709  prefix().state = to_enqueue;
710  }
711 #endif /* __TBB_RECYCLE_TO_ENQUEUE */
712 
713  //------------------------------------------------------------------------
714  // Spawning and blocking
715  //------------------------------------------------------------------------
716 
718  void set_ref_count( int count ) {
719 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
721 #else
722  prefix().ref_count = count;
723 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
724  }
725 
727 
730  }
731 
733 
734  int add_ref_count( int count ) {
736  internal::reference_count k = count+__TBB_FetchAndAddW( &prefix().ref_count, count );
737  __TBB_ASSERT( k>=0, "task's reference count underflowed" );
738  if( k==0 )
740  return int(k);
741  }
742 
744 
746 #if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
748 #else
750 #endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
751  }
752 
754  using task_base::spawn;
755 
757  void spawn_and_wait_for_all( task& child ) {
758  prefix().owner->wait_for_all( *this, &child );
759  }
760 
763 
765  static void spawn_root_and_wait( task& root ) {
766  root.prefix().owner->spawn_root_and_wait( root, root.prefix().next );
767  }
768 
770 
772  static void spawn_root_and_wait( task_list& root_list );
773 
775 
776  void wait_for_all() {
777  prefix().owner->wait_for_all( *this, NULL );
778  }
779 
781 #if __TBB_TASK_PRIORITY
782 
792 #endif /* __TBB_TASK_PRIORITY */
793  static void enqueue( task& t ) {
794  t.prefix().owner->enqueue( t, NULL );
795  }
796 
797 #if __TBB_TASK_PRIORITY
798  static void enqueue( task& t, priority_t p ) {
800  __TBB_ASSERT( p == priority_low || p == priority_normal || p == priority_high, "Invalid priority level value" );
801  t.prefix().owner->enqueue( t, (void*)p );
802  }
803 #endif /* __TBB_TASK_PRIORITY */
804 
806  static task& __TBB_EXPORTED_FUNC self();
807 
809  task* parent() const {return prefix().parent;}
810 
812  void set_parent(task* p) {
813 #if __TBB_TASK_GROUP_CONTEXT
814  __TBB_ASSERT(!p || prefix().context == p->prefix().context, "The tasks must be in the same context");
815 #endif
816  prefix().parent = p;
817  }
818 
819 #if __TBB_TASK_GROUP_CONTEXT
820 
822  task_group_context* context() {return prefix().context;}
823 
825  task_group_context* group () { return prefix().context; }
826 #endif /* __TBB_TASK_GROUP_CONTEXT */
827 
829  bool is_stolen_task() const {
830  return (prefix().extra_state & 0x80)!=0;
831  }
832 
833  //------------------------------------------------------------------------
834  // Debugging
835  //------------------------------------------------------------------------
836 
838  state_type state() const {return state_type(prefix().state);}
839 
841  int ref_count() const {
842 #if TBB_USE_ASSERT
843  internal::reference_count ref_count_ = prefix().ref_count;
844  __TBB_ASSERT( ref_count_==int(ref_count_), "integer overflow error");
845 #endif
846  return int(prefix().ref_count);
847  }
848 
851 
852  //------------------------------------------------------------------------
853  // Affinity
854  //------------------------------------------------------------------------
855 
857 
859 
861  void set_affinity( affinity_id id ) {prefix().affinity = id;}
862 
864  affinity_id affinity() const {return prefix().affinity;}
865 
867 
872 
873 #if __TBB_TASK_GROUP_CONTEXT
874 
886 
888 
889  bool cancel_group_execution () { return prefix().context->cancel_group_execution(); }
890 
892  bool is_cancelled () const { return prefix().context->is_group_execution_cancelled(); }
893 #else
894  bool is_cancelled () const { return false; }
895 #endif /* __TBB_TASK_GROUP_CONTEXT */
896 
897 #if __TBB_TASK_PRIORITY
898  void set_group_priority ( priority_t p ) { prefix().context->set_priority(p); }
900 
902  priority_t group_priority () const { return prefix().context->priority(); }
903 
904 #endif /* __TBB_TASK_PRIORITY */
905 
906 private:
908  friend class task_list;
909  friend class internal::scheduler;
911 #if __TBB_TASK_GROUP_CONTEXT
913 #endif /* __TBB_TASK_GROUP_CONTEXT */
917 
919 
920  internal::task_prefix& prefix( internal::version_tag* = NULL ) const {
921  return reinterpret_cast<internal::task_prefix*>(const_cast<task*>(this))[-1];
922  }
923 }; // class task
924 
926 
927 class empty_task: public task {
929  return NULL;
930  }
931 };
932 
934 namespace internal {
935  template<typename F>
936  class function_task : public task {
937 #if __TBB_ALLOW_MUTABLE_FUNCTORS
938  F my_func;
939 #else
940  const F my_func;
941 #endif
943  my_func();
944  return NULL;
945  }
946  public:
947  function_task( const F& f ) : my_func(f) {}
948 #if __TBB_CPP11_RVALUE_REF_PRESENT
949  function_task( F&& f ) : my_func( std::move(f) ) {}
950 #endif
951  };
952 } // namespace internal
954 
956 
958 class task_list: internal::no_copy {
959 private:
962  friend class task;
964 public:
966  task_list() : first(NULL), next_ptr(&first) {}
967 
970 
972  bool empty() const {return !first;}
973 
975  void push_back( task& task ) {
976  task.prefix().next = NULL;
977  *next_ptr = &task;
978  next_ptr = &task.prefix().next;
979  }
980 #if __TBB_TODO
981  // TODO: add this method and implement&document the local execution ordering. See more in generic_scheduler::local_spawn
983  void push_front( task& task ) {
984  if( empty() ) {
985  push_back(task);
986  } else {
987  task.prefix().next = first;
988  first = &task;
989  }
990  }
991 #endif
992  task& pop_front() {
994  __TBB_ASSERT( !empty(), "attempt to pop item from empty task_list" );
995  task* result = first;
996  first = result->prefix().next;
997  if( !first ) next_ptr = &first;
998  return *result;
999  }
1000 
1002  void clear() {
1003  first=NULL;
1004  next_ptr=&first;
1005  }
1006 };
1007 
1009  t.prefix().owner->spawn( t, t.prefix().next );
1010 }
1011 
1013  if( task* t = list.first ) {
1014  t->prefix().owner->spawn( *t, *list.next_ptr );
1015  list.clear();
1016  }
1017 }
1018 
1019 inline void task::spawn_root_and_wait( task_list& root_list ) {
1020  if( task* t = root_list.first ) {
1021  t->prefix().owner->spawn_root_and_wait( *t, *root_list.next_ptr );
1022  root_list.clear();
1023  }
1024 }
1025 
1026 } // namespace tbb
1027 
1028 inline void *operator new( size_t bytes, const tbb::internal::allocate_root_proxy& ) {
1030 }
1031 
1032 inline void operator delete( void* task, const tbb::internal::allocate_root_proxy& ) {
1033  tbb::internal::allocate_root_proxy::free( *static_cast<tbb::task*>(task) );
1034 }
1035 
1036 #if __TBB_TASK_GROUP_CONTEXT
1037 inline void *operator new( size_t bytes, const tbb::internal::allocate_root_with_context_proxy& p ) {
1038  return &p.allocate(bytes);
1039 }
1040 
1041 inline void operator delete( void* task, const tbb::internal::allocate_root_with_context_proxy& p ) {
1042  p.free( *static_cast<tbb::task*>(task) );
1043 }
1044 #endif /* __TBB_TASK_GROUP_CONTEXT */
1045 
1046 inline void *operator new( size_t bytes, const tbb::internal::allocate_continuation_proxy& p ) {
1047  return &p.allocate(bytes);
1048 }
1049 
1050 inline void operator delete( void* task, const tbb::internal::allocate_continuation_proxy& p ) {
1051  p.free( *static_cast<tbb::task*>(task) );
1052 }
1053 
1054 inline void *operator new( size_t bytes, const tbb::internal::allocate_child_proxy& p ) {
1055  return &p.allocate(bytes);
1056 }
1057 
1058 inline void operator delete( void* task, const tbb::internal::allocate_child_proxy& p ) {
1059  p.free( *static_cast<tbb::task*>(task) );
1060 }
1061 
1062 inline void *operator new( size_t bytes, const tbb::internal::allocate_additional_child_of_proxy& p ) {
1063  return &p.allocate(bytes);
1064 }
1065 
1066 inline void operator delete( void* task, const tbb::internal::allocate_additional_child_of_proxy& p ) {
1067  p.free( *static_cast<tbb::task*>(task) );
1068 }
1069 
1070 #endif /* __TBB_task_H */
void __TBB_EXPORTED_METHOD free(task &) const
Definition: task.cpp:138
task object is freshly allocated or recycled.
Definition: task.h:604
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.
Definition: task.h:81
friend class internal::allocate_root_with_context_proxy
Definition: task.h:912
static const int priority_stride_v4
Definition: task.h:276
static void enqueue(task &t)
Enqueue task for starvation-resistant execution.
Definition: task.h:793
void set_ref_count(int count)
Set reference count.
Definition: task.h:718
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
static const kind_type binding_completed
Definition: task.h:551
void __TBB_EXPORTED_METHOD change_group(task_group_context &ctx)
Moves this task from its current group into another one.
state_type
Enumeration of task states that the scheduler considers.
Definition: task.h:596
A list of children.
Definition: task.h:958
bool __TBB_EXPORTED_METHOD cancel_group_execution()
Initiates cancellation of all tasks in this cancellation group and its subordinate groups.
void set_parent(task *p)
sets parent task pointer to specified value
Definition: task.h:812
priority_t group_priority() const
Retrieves current priority of the task group this task belongs to.
Definition: task.h:902
void copy_fp_settings(const task_group_context &src)
Copies FPU control setting from another context.
task * next_offloaded
Pointer to the next offloaded lower priority task.
Definition: task.h:225
task_group_context * my_parent
Pointer to the context of the parent cancellation group. NULL for isolated contexts.
Definition: task.h:371
Base class for user-defined tasks.
Definition: task.h:576
Work stealing task scheduler.
Definition: scheduler.h:115
virtual ~task()
Destructor.
Definition: task.h:590
#define __TBB_EXPORTED_FUNC
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:220
static const kind_type detached
Definition: task.h:552
task()
Default constructor.
Definition: task.h:586
tbb::task & task()
The task corresponding to this task_prefix.
Definition: task.h:266
virtual void wait_for_all(task &parent, task *child)=0
For internal use only.
task_group_context * context
Shared context that is used to communicate asynchronous state changes.
Definition: task.h:203
task &__TBB_EXPORTED_METHOD allocate(size_t size) const
Definition: task.cpp:118
task &__TBB_EXPORTED_METHOD allocate(size_t size) const
bool __TBB_EXPORTED_METHOD is_owned_by_current_thread() const
Obsolete, and only retained for the sake of backward compatibility. Always returns true.
Definition: task.cpp:212
isolation_tag isolation
The tag used for task isolation.
Definition: task.h:193
static task &__TBB_EXPORTED_FUNC allocate(size_t size)
Definition: task.cpp:39
void __TBB_EXPORTED_METHOD init()
Out-of-line part of the constructor.
internal::reference_count __TBB_EXPORTED_METHOD internal_decrement_ref_count()
Decrement reference count and return its new value.
Definition: task.cpp:196
Memory prefix to a task object.
Definition: task.h:180
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:335
internal::tbb_exception_ptr exception_container_type
Definition: task.h:328
friend class task
Definition: task.h:962
int depth
Obsolete. Used to be scheduling depth before TBB 2.2.
Definition: task.h:245
void increment_ref_count()
Atomically increment reference count.
Definition: task.h:728
unsigned char extra_state
Miscellaneous state that is not directly visible to users, stored as a byte for compactness.
Definition: task.h:258
void wait_for_all()
Wait for reference count to become one, and set reference count to zero.
Definition: task.h:776
virtual void __TBB_EXPORTED_METHOD note_affinity(affinity_id id)
Invoked by scheduler to notify task that it ran on unexpected thread.
Definition: task.cpp:249
void propagate_task_group_state(T task_group_context::*mptr_state, task_group_context &src, T new_state)
Propagates any state change detected to *this, and as an optimisation possibly also upward along the ...
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 parent
virtual void spawn(task &first, task *&next)=0
For internal use only.
task_group_context(internal::string_index name)
Definition: task.h:475
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:102
scheduler * owner
Obsolete. The scheduler that owns the task.
Definition: task.h:220
internal::cpu_ctl_env_space my_cpu_ctl_env
Space for platform-specific FPU settings.
Definition: task.h:397
task is running, and will be destroyed after method execute() completes.
Definition: task.h:598
void __TBB_EXPORTED_METHOD reset()
Forcefully reinitializes the context after the task tree it was associated with is completed.
friend class internal::allocate_child_proxy
Definition: task.h:187
friend class internal::allocate_additional_child_of_proxy
Definition: task.h:916
friend class internal::allocate_continuation_proxy
Definition: task.h:914
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
auto first(Container &c) -> decltype(begin(c))
#define __TBB_override
Definition: tbb_stddef.h:244
void const char const char int ITT_FORMAT __itt_group_sync p
task & pop_front()
Pop the front task from the list.
Definition: task.h:993
task_group_context * context()
This method is deprecated and will be removed in the future.
Definition: task.h:822
friend class internal::scheduler
Definition: task.h:909
scheduler * origin
The scheduler that allocated the task, or NULL if the task is big.
Definition: task.h:212
void push_back(task &task)
Push task onto back of list.
Definition: task.h:975
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads.
friend class internal::allocate_root_proxy
Definition: task.h:186
virtual void enqueue(task &t, void *reserved)=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 size
void set_priority(priority_t)
Changes priority of the task group.
Base class for types that should not be assigned.
Definition: tbb_stddef.h:324
friend class internal::allocate_additional_child_of_proxy
Definition: task.h:189
task_group_context(kind_type relation_with_parent=bound, uintptr_t t=default_traits)
Default & binding constructor.
Definition: task.h:465
friend class internal::scheduler
Definition: task.h:185
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
__itt_caller itt_caller
Used to set and maintain stack stitching point for Intel Performance Tools.
Definition: task.h:379
__TBB_EXPORTED_METHOD ~task_group_context()
bool cancel_group_execution()
Initiates cancellation of all tasks in this cancellation group and its subordinate groups.
Definition: task.h:889
static const kind_type binding_required
Definition: task.h:550
bool is_cancelled() const
Returns true if the context has received cancellation request.
Definition: task.h:892
priority_t priority() const
Retrieves current priority of the current task group.
internal::context_list_node_t my_node
Used to form the thread specific list of contexts without additional memory allocation.
Definition: task.h:376
task is in ready pool, or is going to be put there, or was just taken off.
Definition: task.h:602
void __TBB_EXPORTED_METHOD free(task &) const
Definition: task.cpp:125
affinity_id affinity() const
Current affinity of this task.
Definition: task.h:864
void recycle_to_reexecute()
Schedule this for reexecution after current execute() returns.
Definition: task.h:698
task_group_context * group()
Pointer to the task group descriptor.
Definition: task.h:825
allocate_root_with_context_proxy(task_group_context &ctx)
Definition: task.h:141
internal::generic_scheduler * my_owner
Scheduler instance that registered this context in its thread specific list.
Definition: task.h:413
Used to form groups of tasks.
Definition: task.h:319
friend class internal::allocate_root_with_context_proxy
Definition: task.h:548
task &__TBB_EXPORTED_METHOD allocate(size_t size) const
Definition: task.cpp:132
struct ___itt_caller * __itt_caller
Definition: task.h:29
void call_itt_notify(notify_type, void *)
task * first
Definition: task.h:960
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:309
Class delimiting the scope of task scheduler activity.
intptr_t my_priority
Priority level of the task group (in normalized representation)
Definition: task.h:420
friend class internal::allocate_child_proxy
Definition: task.h:915
virtual ~scheduler()=0
Pure virtual destructor;.
Definition: scheduler.cpp:76
task * self
No longer used, but retained for binary layout compatibility. Always NULL.
Definition: task.h:49
Base class for methods that became static in TBB 3.0.
Definition: task.h:68
friend class internal::generic_scheduler
Definition: task.h:321
intptr_t isolation_tag
A tag for task isolation.
Definition: task.h:126
void __TBB_EXPORTED_METHOD free(task &) const
internal::affinity_id affinity_id
An id as used for specifying affinity.
Definition: task.h:858
context_list_node_t * my_prev
Definition: task.h:134
internal::allocate_child_proxy & allocate_child()
Returns proxy for overloaded new that allocates a child task of *this.
Definition: task.h:638
task * parent() const
task on whose behalf this task is working, or NULL if this is a root.
Definition: task.h:809
uintptr_t my_version_and_traits
Version for run-time checks and behavioral traits of the context.
Definition: task.h:407
void __TBB_EXPORTED_METHOD register_pending_exception()
Records the pending exception, and cancels the task group.
int add_ref_count(int count)
Atomically adds to reference count and returns its new value.
Definition: task.h:734
state_type state() const
Current execution state.
Definition: task.h:838
int space[sizeof(internal::uint64_t)/sizeof(int)]
Definition: task.h:57
void __TBB_EXPORTED_METHOD free(task &) const
Definition: task.cpp:109
task to be recycled as continuation
Definition: task.h:608
The graph class.
task * execute() __TBB_override
Should be overridden by derived classes.
Definition: task.h:942
task * execute() __TBB_override
Should be overridden by derived classes.
Definition: task.h:928
task_list()
Construct empty list.
Definition: task.h:966
affinity_id affinity
Definition: task.h:260
void set_group_priority(priority_t p)
Changes priority of the task group this task belongs to.
Definition: task.h:899
bool is_stolen_task() const
True if task was stolen from the task pool of another thread.
Definition: task.h:829
bool empty() const
True if list if empty; false otherwise.
Definition: task.h:972
void recycle_as_safe_continuation()
Recommended to use, safe variant of recycle_as_continuation.
Definition: task.h:676
#define __TBB_FetchAndIncrementWacquire(P)
Definition: tbb_machine.h:314
int ref_count() const
The internal reference count.
Definition: task.h:841
static void spawn_root_and_wait(task &root)
Spawn task allocated by allocate_root, wait for it to complete, and deallocate it.
Definition: task.h:765
char _leading_padding[internal::NFS_MaxLineSize - 2 *sizeof(uintptr_t) - sizeof(void *) - sizeof(internal::context_list_node_t) - sizeof(__itt_caller) - sizeof(internal::cpu_ctl_env_space)]
Leading padding protecting accesses to frequently used members from false sharing.
Definition: task.h:391
virtual void spawn_root_and_wait(task &first, task *&next)=0
For internal use only.
exception_container_type * my_exception
Pointer to the container storing exception being propagated across this task group.
Definition: task.h:410
unsigned short affinity_id
An id as used for specifying affinity.
Definition: task.h:122
void register_with(internal::generic_scheduler *local_sched)
Registers this context with the local scheduler.
#define __TBB_FetchAndDecrementWrelease(P)
Definition: tbb_machine.h:315
static void spawn(task &t)
Schedule task for execution when a worker becomes available.
Definition: task.h:1008
char _trailing_padding[internal::NFS_MaxLineSize - 2 *sizeof(uintptr_t) - 2 *sizeof(void *) - sizeof(intptr_t) - sizeof(internal::string_index)]
Trailing padding protecting accesses to frequently used members from false sharing.
Definition: task.h:433
task &__TBB_EXPORTED_METHOD allocate(size_t size) const
Definition: task.cpp:100
__TBB_atomic reference_count ref_count
Reference count used for synchronization.
Definition: task.h:240
uintptr_t _my_kind_aligner
Definition: task.h:367
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 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
void spawn_and_wait_for_all(task &child)
Similar to spawn followed by wait_for_all, but more efficient.
Definition: task.h:757
task object is on free list, or is going to be put there, or was just taken off.
Definition: task.h:606
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:620
int decrement_ref_count()
Atomically decrement reference count and returns its new value.
Definition: task.h:745
static void __TBB_EXPORTED_FUNC destroy(task &victim)
Destroy a task.
Definition: task.cpp:216
__TBB_atomic kind_type my_kind
Flavor of this context: bound or isolated.
Definition: task.h:366
uintptr_t my_state
Internal state (combination of state flags, currently only may_have_children).
Definition: task.h:416
task that does nothing. Useful for synchronization.
Definition: task.h:927
static const kind_type dying
Definition: task.h:553
void set_affinity(affinity_id id)
Set affinity for this task.
Definition: task.h:861
#define __TBB_TASK_BASE_ACCESS
Definition: task.h:42
function_task(const F &f)
Definition: task.h:947
tbb::task * parent
The task whose reference count includes me.
Definition: task.h:233
void bind_to(internal::generic_scheduler *local_sched)
Registers this context with the local scheduler and binds it to its parent context.
task ** next_ptr
Definition: task.h:961
uintptr_t traits() const
Returns the context's trait.
Definition: task.h:539
internal::allocate_continuation_proxy & allocate_continuation()
Returns proxy for overloaded new that allocates a continuation task of *this.
Definition: task.h:633
virtual task * execute()=0
Should be overridden by derived classes.
task to be rescheduled.
Definition: task.h:600
internal::task_prefix & prefix(internal::version_tag *=NULL) const
Get reference to corresponding task_prefix.
Definition: task.h:920
friend class internal::allocate_continuation_proxy
Definition: task.h:188
void recycle_as_continuation()
Change this to be a continuation of its former self.
Definition: task.h:668
intptr_t reference_count
A reference count.
Definition: task.h:119
static void __TBB_EXPORTED_FUNC free(task &)
Definition: task.cpp:51
version_tag_v3 version_tag
Definition: tbb_stddef.h:390
void __TBB_EXPORTED_METHOD capture_fp_settings()
Captures the current FPU control settings to the context.
~task_list()
Destroys the list, but does not destroy the task objects.
Definition: task.h:969
const isolation_tag no_isolation
Definition: task.h:127
void __TBB_EXPORTED_METHOD internal_set_ref_count(int count)
Set reference count.
Definition: task.cpp:187
uintptr_t my_cancellation_requested
Specifies whether cancellation was requested for this task group.
Definition: task.h:401
unsigned char state
A task::state_type, stored as a byte for compactness.
Definition: task.h:249
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
void clear()
Clear the list.
Definition: task.h:1002
#define __TBB_atomic
Definition: tbb_stddef.h:241
void recycle_as_child_of(task &new_parent)
Change this to be a child of new_parent.
Definition: task.h:682
tbb::task * next
"next" field for list of task
Definition: task.h:263
context_list_node_t * my_next
Definition: task.h:134
friend class internal::allocate_root_proxy
Definition: task.h:910
priority_t
Definition: task.h:279
bool __TBB_EXPORTED_METHOD is_group_execution_cancelled() const
Returns true if the context received cancellation request.
internal::string_index my_name
Decription of algorithm for scheduler based instrumentation.
Definition: task.h:424

Copyright © 2005-2018 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.