27 #if __TBB_TASK_GROUP_CONTEXT 29 using namespace internal;
35 inline char* duplicate_string (
const char* src ) {
38 size_t len = strlen(src) + 1;
40 strncpy (dst, src, len);
50 my_exception_name = duplicate_string( a_name );
51 my_exception_info = duplicate_string( info );
62 ::new (e) captured_exception();
63 e->my_exception_name = my_exception_name;
64 e->my_exception_info = my_exception_info;
66 my_exception_name = my_exception_info = NULL;
72 __TBB_ASSERT ( my_dynamic,
"Method destroy can be used only on objects created by clone or allocate" );
82 ::new (e) captured_exception(a_name, info);
89 return my_exception_name;
93 return my_exception_info;
101 #if !TBB_USE_CAPTURED_EXCEPTION 106 tbb_exception_ptr* AllocateExceptionContainer(
const T& src ) {
109 new (eptr) tbb_exception_ptr(src);
114 return AllocateExceptionContainer( std::current_exception() );
118 return AllocateExceptionContainer( std::current_exception() );
122 tbb_exception_ptr *res = AllocateExceptionContainer( src );
128 this->tbb_exception_ptr::~tbb_exception_ptr();
144 uintptr_t local_count_snapshot = my_owner->my_context_state_propagation_epoch;
145 my_owner->my_local_ctx_list_update.store<
relaxed>(1);
149 if ( my_owner->my_nonlocal_ctx_list_update.load<
relaxed>() ) {
151 my_node.my_prev->my_next = my_node.my_next;
152 my_node.my_next->my_prev = my_node.my_prev;
153 my_owner->my_local_ctx_list_update.store<
relaxed>(0);
156 my_node.my_prev->my_next = my_node.my_next;
157 my_node.my_next->my_prev = my_node.my_prev;
161 my_owner->my_local_ctx_list_update.store<
release>(0);
162 if ( local_count_snapshot != the_context_state_propagation_epoch ) {
176 my_node.my_prev->my_next = my_node.my_next;
177 my_node.my_next->my_prev = my_node.my_prev;
181 my_owner->my_nonlocal_ctx_list_update.fetch_and_increment<
full_fence>();
184 my_owner->my_context_list_mutex.lock();
185 my_node.my_prev->my_next = my_node.my_next;
186 my_node.my_next->my_prev = my_node.my_prev;
187 my_owner->my_context_list_mutex.unlock();
189 my_owner->my_nonlocal_ctx_list_update.fetch_and_decrement<
full_fence>();
194 internal::punned_cast<cpu_ctl_env*>(&my_cpu_ctl_env)->~cpu_ctl_env();
198 my_exception->destroy();
205 if( ( my_version_and_traits & version_mask ) < 3 )
206 my_name = internal::CUSTOM_CTX;
209 __TBB_STATIC_ASSERT (
sizeof(my_version_and_traits) >= 4,
"Layout of my_version_and_traits must be reconsidered on this platform" );
211 __TBB_ASSERT ( (uintptr_t(
this) & (
sizeof(my_cancellation_requested) - 1)) == 0,
"Context is improperly aligned" );
214 my_cancellation_requested = 0;
219 #if __TBB_TASK_PRIORITY 220 my_priority = normalized_normal_priority;
223 __TBB_STATIC_ASSERT(
sizeof(my_cpu_ctl_env) ==
sizeof(internal::uint64_t),
"The reserved space for FPU settings are not equal sizeof(uint64_t)" );
224 __TBB_STATIC_ASSERT(
sizeof(cpu_ctl_env) <=
sizeof(my_cpu_ctl_env),
"FPU settings storage does not fit to uint64_t" );
227 cpu_ctl_env &ctl = *internal::punned_cast<cpu_ctl_env*>(&my_cpu_ctl_env);
228 new ( &ctl ) cpu_ctl_env;
229 if ( my_version_and_traits & fp_settings )
236 my_owner = local_sched;
238 my_node.my_prev = &local_sched->my_context_list_head;
241 local_sched->my_local_ctx_list_update.store<
relaxed>(1);
247 if ( local_sched->my_nonlocal_ctx_list_update.load<
relaxed>() ) {
249 local_sched->my_context_list_head.my_next->my_prev = &my_node;
250 my_node.my_next = local_sched->my_context_list_head.my_next;
251 my_owner->my_local_ctx_list_update.store<
relaxed>(0);
252 local_sched->my_context_list_head.my_next = &my_node;
255 local_sched->my_context_list_head.my_next->my_prev = &my_node;
256 my_node.my_next = local_sched->my_context_list_head.my_next;
257 my_owner->my_local_ctx_list_update.store<
release>(0);
268 __TBB_ASSERT ( !my_parent,
"Parent is set before initial binding" );
269 my_parent = local_sched->my_innermost_running_task->prefix().context;
272 if ( !(my_version_and_traits & fp_settings) )
273 copy_fp_settings(*my_parent);
277 if ( !(my_parent->my_state & may_have_children) )
278 my_parent->my_state |= may_have_children;
279 if ( my_parent->my_parent ) {
291 uintptr_t local_count_snapshot =
__TBB_load_with_acquire( my_parent->my_owner->my_context_state_propagation_epoch );
294 my_cancellation_requested = my_parent->my_cancellation_requested;
295 #if __TBB_TASK_PRIORITY 296 my_priority = my_parent->my_priority;
298 register_with( local_sched );
304 if ( local_count_snapshot != the_context_state_propagation_epoch ) {
306 context_state_propagation_mutex_type::scoped_lock
lock(the_context_state_propagation_mutex);
307 my_cancellation_requested = my_parent->my_cancellation_requested;
308 #if __TBB_TASK_PRIORITY 309 my_priority = my_parent->my_priority;
314 register_with( local_sched );
318 my_cancellation_requested = my_parent->my_cancellation_requested;
319 #if __TBB_TASK_PRIORITY 320 my_priority = my_parent->my_priority;
326 template <
typename T>
328 if (this->*mptr_state == new_state) {
336 else if (
this == &src) {
343 for ( task_group_context *ancestor = my_parent; ancestor != NULL; ancestor = ancestor->my_parent ) {
344 __TBB_ASSERT(internal::is_alive(ancestor->my_version_and_traits),
"context tree was corrupted");
345 if ( ancestor == &src ) {
346 for ( task_group_context *ctx =
this; ctx != ancestor; ctx = ctx->my_parent )
347 ctx->*mptr_state = new_state;
354 template <
typename T>
355 void generic_scheduler::propagate_task_group_state ( T task_group_context::*mptr_state, task_group_context& src, T new_state ) {
361 while ( node != &my_context_list_head ) {
363 if ( ctx.*mptr_state != new_state )
364 ctx.propagate_task_group_state( mptr_state, src, new_state );
365 node = node->my_next;
366 __TBB_ASSERT( is_alive(ctx.my_version_and_traits),
"Local context list contains destroyed object" );
373 template <
typename T>
374 bool market::propagate_task_group_state ( T task_group_context::*mptr_state, task_group_context& src, T new_state ) {
380 context_state_propagation_mutex_type::scoped_lock
lock(the_context_state_propagation_mutex);
381 if ( src.*mptr_state != new_state )
388 for (
unsigned i = 0; i < num_workers; ++i ) {
392 s->propagate_task_group_state( mptr_state, src, new_state );
396 for( scheduler_list_type::iterator it = my_masters.begin(); it != my_masters.end(); it++ )
397 it->propagate_task_group_state( mptr_state, src, new_state );
402 __TBB_ASSERT ( my_cancellation_requested == 0 || my_cancellation_requested == 1,
"Invalid cancellation state");
403 if ( my_cancellation_requested ||
as_atomic(my_cancellation_requested).compare_and_swap(1, 0) ) {
414 return my_cancellation_requested != 0;
422 if ( my_exception ) {
423 my_exception->destroy();
426 my_cancellation_requested = 0;
435 cpu_ctl_env &ctl = *internal::punned_cast<cpu_ctl_env*>(&my_cpu_ctl_env);
436 if ( !(my_version_and_traits & fp_settings) ) {
437 new ( &ctl ) cpu_ctl_env;
438 my_version_and_traits |= fp_settings;
444 __TBB_ASSERT( !(my_version_and_traits & fp_settings),
"The context already has FPU settings." );
445 __TBB_ASSERT( src.my_version_and_traits & fp_settings,
"The source context does not have FPU settings." );
447 cpu_ctl_env &ctl = *internal::punned_cast<cpu_ctl_env*>(&my_cpu_ctl_env);
448 cpu_ctl_env &src_ctl = *internal::punned_cast<cpu_ctl_env*>(&src.my_cpu_ctl_env);
449 new (&ctl) cpu_ctl_env( src_ctl );
450 my_version_and_traits |= fp_settings;
455 if ( my_cancellation_requested )
457 #if TBB_USE_EXCEPTIONS 460 } TbbCatchAll(
this );
464 #if __TBB_TASK_PRIORITY 467 intptr_t
p = normalize_priority(prio);
485 s->my_market->update_arena_priority( *
s->my_arena,
p );
489 return static_cast<priority_t>(priority_from_normalized_rep[my_priority]);
#define ITT_STACK(precond, name, obj)
__TBB_EXPORTED_METHOD ~task_group_context()
const char *__TBB_EXPORTED_METHOD name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
void __TBB_EXPORTED_METHOD register_pending_exception()
Records the pending exception, and cancels the task group.
#define __TBB_get_object_ref(class_name, member_name, member_addr)
Returns address of the object containing a member with the given name and address.
T __TBB_load_with_acquire(const volatile T &location)
#define __TBB_STATIC_ASSERT(condition, msg)
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
priority_t priority() const
Retrieves current priority of the current task group.
#define ITT_TASK_GROUP(type, name, parent)
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
#define __TBB_FetchAndAddWrelease(P, V)
static generic_scheduler * local_scheduler_if_initialized()
bool __TBB_EXPORTED_METHOD cancel_group_execution()
Initiates cancellation of all tasks in this cancellation group and its subordinate groups.
task is running, and will be destroyed after method execute() completes.
static tbb_exception_ptr * allocate()
void bind_to(internal::generic_scheduler *local_sched)
Registers this context with the local scheduler and binds it to its parent context.
void atomic_fence()
Sequentially consistent full memory fence.
market * my_market
The market I am in.
void const char const char int ITT_FORMAT __itt_group_sync p
void __TBB_EXPORTED_METHOD reset()
Forcefully reinitializes the context after the task tree it was associated with is completed.
__TBB_EXPORTED_METHOD ~captured_exception()
void __TBB_store_relaxed(volatile T &location, V 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 __itt_model_task_instance ITT_FORMAT p void * lock
void __TBB_EXPORTED_METHOD clear()
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
captured_exception *__TBB_EXPORTED_METHOD move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
void set_priority(priority_t)
Changes priority of the task group.
uintptr_t my_cancellation_requested
Specifies whether cancellation was requested for this task group.
static captured_exception * allocate(const char *name, const char *info)
Functionally equivalent to {captured_exception e(name,info); return e.move();}.
intptr_t my_priority
Priority level of the task group (in normalized representation)
atomic< unsigned > my_first_unused_worker_idx
First unused index of worker.
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 __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
bool __TBB_EXPORTED_METHOD is_group_execution_cancelled() const
Returns true if the context received cancellation request.
void spin_wait_until_eq(const volatile T &location, const U value)
Spin UNTIL the value of the variable is equal to a given value.
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
void const char const char int ITT_FORMAT __itt_group_sync s
static generic_scheduler * local_scheduler_weak()
T __TBB_load_relaxed(const volatile T &location)
static bool is_set(generic_scheduler *s)
Used to check validity of the local scheduler TLS contents.
const char *__TBB_EXPORTED_METHOD what() const __TBB_override
Returns the result of originally intercepted exception's what() method.
void __TBB_EXPORTED_METHOD set(const char *name, const char *info)
void __TBB_EXPORTED_METHOD init()
Out-of-line part of the constructor.
void copy_fp_settings(const task_group_context &src)
Copies FPU control setting from another context.
void register_with(internal::generic_scheduler *local_sched)
Registers this context with the local scheduler.
void __TBB_EXPORTED_METHOD capture_fp_settings()
Captures the current FPU control settings to the context.
void __TBB_store_with_release(volatile T &location, V value)
atomic< T > & as_atomic(T &t)
friend class generic_scheduler
void __TBB_EXPORTED_METHOD destroy() __TBB_override
Destroys objects created by the move() method.
void destroy()
Destroys this objects.