11/*
2- Copyright (c) 2005-2023 Intel Corporation
2+ Copyright (c) 2005-2025 Intel Corporation
3+ Copyright (c) 2025 UXL Foundation Contributors
34
45 Licensed under the Apache License, Version 2.0 (the "License");
56 you may not use this file except in compliance with the License.
@@ -42,9 +43,11 @@ void tbb_exception_ptr::destroy() noexcept {
4243 deallocate_memory (this );
4344}
4445
45- void tbb_exception_ptr::throw_self () {
46+ void tbb_exception_ptr::rethrow_and_destroy () {
47+ auto temp_ptr = my_ptr;
48+ destroy ();
4649 if (governor::rethrow_exception_broken ()) fix_broken_rethrow ();
47- std::rethrow_exception (my_ptr );
50+ std::rethrow_exception (temp_ptr );
4851}
4952
5053// ------------------------------------------------------------------------
@@ -65,10 +68,7 @@ void task_group_context_impl::destroy(d1::task_group_context& ctx) {
6568#endif
6669 ctl->~cpu_ctl_env ();
6770
68- auto exception = ctx.my_exception .load (std::memory_order_relaxed);
69- if (exception) {
70- exception->destroy ();
71- }
71+ handle_context_exception (ctx, /* rethrow = */ false );
7272 ITT_STACK_DESTROY (ctx.my_itt_caller );
7373
7474 poison_pointer (ctx.my_parent );
@@ -240,19 +240,14 @@ bool task_group_context_impl::is_group_execution_cancelled(const d1::task_group_
240240 return ctx.my_cancellation_requested .load (std::memory_order_relaxed) != 0 ;
241241}
242242
243- // IMPORTANT: It is assumed that this method is not used concurrently!
243+ // IMPORTANT: If used while tasks are in the context, the cancellation signal can be lost
244244void task_group_context_impl::reset (d1::task_group_context& ctx) {
245245 __TBB_ASSERT (!is_poisoned (ctx.my_context_list ), nullptr );
246246 // ! TODO: Add assertion that this context does not have children
247- // No fences are necessary since this context can be accessed from another thread
248- // only after stealing happened (which means necessary fences were used).
247+
248+ handle_context_exception (ctx, /* rethrow = */ false );
249249
250- auto exception = ctx.my_exception .load (std::memory_order_relaxed);
251- if (exception) {
252- exception->destroy ();
253- ctx.my_exception .store (nullptr , std::memory_order_relaxed);
254- }
255- ctx.my_cancellation_requested = 0 ;
250+ ctx.my_cancellation_requested .store (0 , std::memory_order_relaxed);
256251}
257252
258253// IMPORTANT: It is assumed that this method is not used concurrently!
0 commit comments