13 #ifndef KMP_WAIT_RELEASE_H
14 #define KMP_WAIT_RELEASE_H
18 #include "kmp_stats.h"
20 #include "ompt-specific.h"
36 struct flag_properties {
37 unsigned int type : 16;
38 unsigned int reserved : 16;
41 template <enum flag_type FlagType>
struct flag_traits {};
43 template <>
struct flag_traits<flag32> {
44 typedef kmp_uint32 flag_t;
45 static const flag_type t = flag32;
46 static inline flag_t tcr(flag_t f) {
return TCR_4(f); }
47 static inline flag_t test_then_add4(
volatile flag_t *f) {
48 return KMP_TEST_THEN_ADD4_32(RCAST(
volatile kmp_int32 *, f));
50 static inline flag_t test_then_or(
volatile flag_t *f, flag_t v) {
51 return KMP_TEST_THEN_OR32(f, v);
53 static inline flag_t test_then_and(
volatile flag_t *f, flag_t v) {
54 return KMP_TEST_THEN_AND32(f, v);
58 template <>
struct flag_traits<atomic_flag64> {
59 typedef kmp_uint64 flag_t;
60 static const flag_type t = atomic_flag64;
61 static inline flag_t tcr(flag_t f) {
return TCR_8(f); }
62 static inline flag_t test_then_add4(
volatile flag_t *f) {
63 return KMP_TEST_THEN_ADD4_64(RCAST(
volatile kmp_int64 *, f));
65 static inline flag_t test_then_or(
volatile flag_t *f, flag_t v) {
66 return KMP_TEST_THEN_OR64(f, v);
68 static inline flag_t test_then_and(
volatile flag_t *f, flag_t v) {
69 return KMP_TEST_THEN_AND64(f, v);
73 template <>
struct flag_traits<flag64> {
74 typedef kmp_uint64 flag_t;
75 static const flag_type t = flag64;
76 static inline flag_t tcr(flag_t f) {
return TCR_8(f); }
77 static inline flag_t test_then_add4(
volatile flag_t *f) {
78 return KMP_TEST_THEN_ADD4_64(RCAST(
volatile kmp_int64 *, f));
80 static inline flag_t test_then_or(
volatile flag_t *f, flag_t v) {
81 return KMP_TEST_THEN_OR64(f, v);
83 static inline flag_t test_then_and(
volatile flag_t *f, flag_t v) {
84 return KMP_TEST_THEN_AND64(f, v);
88 template <>
struct flag_traits<flag_oncore> {
89 typedef kmp_uint64 flag_t;
90 static const flag_type t = flag_oncore;
91 static inline flag_t tcr(flag_t f) {
return TCR_8(f); }
92 static inline flag_t test_then_add4(
volatile flag_t *f) {
93 return KMP_TEST_THEN_ADD4_64(RCAST(
volatile kmp_int64 *, f));
95 static inline flag_t test_then_or(
volatile flag_t *f, flag_t v) {
96 return KMP_TEST_THEN_OR64(f, v);
98 static inline flag_t test_then_and(
volatile flag_t *f, flag_t v) {
99 return KMP_TEST_THEN_AND64(f, v);
109 std::atomic<bool> *sleepLoc;
112 typedef flag_traits<FlagType> traits_type;
135 enum barrier_type get_bt() {
return bs_last_barrier; }
139 template <
typename PtrType, flag_type FlagType,
bool Sleepable>
142 volatile PtrType *loc;
144 typedef flag_traits<FlagType> traits_type;
147 typedef PtrType flag_t;
155 kmp_flag_native(
volatile PtrType *p, PtrType c, std::atomic<bool> *sloc)
158 void *
operator new(
size_t size) {
return __kmp_allocate(size); }
159 void operator delete(
void *p) { __kmp_free(p); }
160 volatile PtrType *get() {
return loc; }
161 void *get_void_p() {
return RCAST(
void *, CCAST(PtrType *, loc)); }
162 void set(
volatile PtrType *new_loc) { loc = new_loc; }
163 PtrType load() {
return *loc; }
164 void store(PtrType val) { *loc = val; }
167 if (Sleepable && !(this->sleepLoc))
168 return (traits_type::tcr(*(this->get())) & ~KMP_BARRIER_SLEEP_STATE) ==
171 return traits_type::tcr(*(this->get())) ==
checker;
182 return traits_type::tcr(*(this->get())) !=
checker;
187 (void)traits_type::test_then_add4((
volatile PtrType *)this->get());
193 if (this->sleepLoc) {
194 this->sleepLoc->store(
true);
195 return *(this->get());
197 return traits_type::test_then_or((
volatile PtrType *)this->get(),
198 KMP_BARRIER_SLEEP_STATE);
204 if (this->sleepLoc) {
205 this->sleepLoc->store(
false);
208 traits_type::test_then_and((
volatile PtrType *)this->get(),
209 ~KMP_BARRIER_SLEEP_STATE);
215 return this->sleepLoc->load();
216 return old_loc & KMP_BARRIER_SLEEP_STATE;
221 return this->sleepLoc->load();
224 bool is_any_sleeping() {
226 return this->sleepLoc->load();
229 kmp_uint8 *get_stolen() {
return NULL; }
233 template <
typename PtrType, flag_type FlagType,
bool Sleepable>
236 std::atomic<PtrType> *
loc;
239 typedef flag_traits<FlagType> traits_type;
240 typedef PtrType flag_t;
248 kmp_flag_atomic(std::atomic<PtrType> *p, PtrType c, std::atomic<bool> *sloc)
251 std::atomic<PtrType> *
get() {
return loc; }
255 void set(std::atomic<PtrType> *new_loc) {
loc = new_loc; }
257 PtrType
load() {
return loc->load(std::memory_order_acquire); }
259 void store(PtrType val) {
loc->store(val, std::memory_order_release); }
262 if (Sleepable && !(this->sleepLoc))
263 return (this->
load() & ~KMP_BARRIER_SLEEP_STATE) ==
checker;
283 if (this->sleepLoc) {
284 this->sleepLoc->store(
true);
285 return *(this->
get());
287 return KMP_ATOMIC_OR(this->
get(), KMP_BARRIER_SLEEP_STATE);
293 if (this->sleepLoc) {
294 this->sleepLoc->store(
false);
297 KMP_ATOMIC_AND(this->
get(), ~KMP_BARRIER_SLEEP_STATE);
303 return this->sleepLoc->load();
304 return old_loc & KMP_BARRIER_SLEEP_STATE;
309 return this->sleepLoc->load();
312 bool is_any_sleeping() {
314 return this->sleepLoc->load();
317 kmp_uint8 *get_stolen() {
return NULL; }
322 static void __ompt_implicit_task_end(kmp_info_t *this_thr,
323 ompt_state_t ompt_state,
325 int ds_tid = this_thr->th.th_info.ds.ds_tid;
326 if (ompt_state == ompt_state_wait_barrier_implicit) {
327 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
329 void *codeptr = NULL;
330 if (ompt_enabled.ompt_callback_sync_region_wait) {
331 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
332 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
335 if (ompt_enabled.ompt_callback_sync_region) {
336 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
337 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
341 if (!KMP_MASTER_TID(ds_tid)) {
342 if (ompt_enabled.ompt_callback_implicit_task) {
343 int flags = this_thr->th.ompt_thread_info.parallel_flags;
344 flags = (flags & ompt_parallel_league) ? ompt_task_initial
345 : ompt_task_implicit;
346 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
347 ompt_scope_end, NULL, tId, 0, ds_tid, flags);
350 this_thr->th.ompt_thread_info.state = ompt_state_idle;
352 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
363 template <
class C,
bool final_spin,
bool Cancellable =
false,
364 bool Sleepable =
true>
366 __kmp_wait_template(kmp_info_t *this_thr,
367 C *flag USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
368 #if USE_ITT_BUILD && USE_ITT_NOTIFY
369 volatile void *spin = flag->get();
373 int tasks_completed = FALSE;
375 kmp_uint64 poll_count;
376 kmp_uint64 hibernate_goal;
378 kmp_uint32 hibernate;
382 KMP_FSYNC_SPIN_INIT(spin, NULL);
383 if (flag->done_check()) {
384 KMP_FSYNC_SPIN_ACQUIRED(CCAST(
void *, spin));
387 th_gtid = this_thr->th.th_info.ds.ds_gtid;
389 kmp_team_t *team = this_thr->th.th_team;
390 if (team && team->t.t_cancel_request == cancel_parallel)
395 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
true);
398 (
"__kmp_wait_sleep: T#%d waiting for flag(%p)\n", th_gtid, flag));
399 #if KMP_STATS_ENABLED
454 ompt_state_t ompt_entry_state;
456 if (ompt_enabled.enabled) {
457 ompt_entry_state = this_thr->th.ompt_thread_info.state;
458 if (!final_spin || ompt_entry_state != ompt_state_wait_barrier_implicit ||
459 KMP_MASTER_TID(this_thr->th.th_info.ds.ds_tid)) {
460 ompt_lw_taskteam_t *team = NULL;
461 if (this_thr->th.th_team)
462 team = this_thr->th.th_team->t.ompt_serialized_team_info;
464 tId = &(team->ompt_task_info.task_data);
466 tId = OMPT_CUR_TASK_DATA(this_thr);
469 tId = &(this_thr->th.ompt_thread_info.task_data);
471 if (final_spin && (__kmp_tasking_mode == tskm_immediate_exec ||
472 this_thr->th.th_task_team == NULL)) {
474 __ompt_implicit_task_end(this_thr, ompt_entry_state, tId);
479 KMP_INIT_YIELD(spins);
480 KMP_INIT_BACKOFF(time);
482 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ||
483 __kmp_pause_status == kmp_soft_paused) {
487 #ifdef KMP_ADJUST_BLOCKTIME
488 if (__kmp_pause_status == kmp_soft_paused ||
489 (__kmp_zero_bt && !this_thr->th.th_team_bt_set))
494 hibernate = this_thr->th.th_team_bt_intervals;
496 hibernate = this_thr->th.th_team_bt_intervals;
507 hibernate += TCR_4(__kmp_global.g.g_time.dt.t_value);
508 KF_TRACE(20, (
"__kmp_wait_sleep: T#%d now=%d, hibernate=%d, intervals=%d\n",
509 th_gtid, __kmp_global.g.g_time.dt.t_value, hibernate,
510 hibernate - __kmp_global.g.g_time.dt.t_value));
512 if (__kmp_pause_status == kmp_soft_paused) {
514 hibernate_goal = KMP_NOW();
516 hibernate_goal = KMP_NOW() + this_thr->th.th_team_bt_intervals;
525 while (flag->notdone_check()) {
526 kmp_task_team_t *task_team = NULL;
527 if (__kmp_tasking_mode != tskm_immediate_exec) {
528 task_team = this_thr->th.th_task_team;
536 if (task_team != NULL) {
537 if (TCR_SYNC_4(task_team->tt.tt_active)) {
538 if (KMP_TASKING_ENABLED(task_team)) {
540 this_thr, th_gtid, final_spin,
541 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj), 0);
543 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
545 KMP_DEBUG_ASSERT(!KMP_MASTER_TID(this_thr->th.th_info.ds.ds_tid));
548 if (final_spin && ompt_enabled.enabled)
549 __ompt_implicit_task_end(this_thr, ompt_entry_state, tId);
551 this_thr->th.th_task_team = NULL;
552 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
555 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
559 KMP_FSYNC_SPIN_PREPARE(CCAST(
void *, spin));
560 if (TCR_4(__kmp_global.g.g_done)) {
561 if (__kmp_global.g.g_abort)
562 __kmp_abort_thread();
568 KMP_YIELD_OVERSUB_ELSE_SPIN(spins, time);
570 #if KMP_STATS_ENABLED
573 if (this_thr->th.th_stats->isIdle() &&
574 KMP_GET_THREAD_STATE() == FORK_JOIN_BARRIER) {
575 KMP_SET_THREAD_STATE(IDLE);
576 KMP_PUSH_PARTITIONED_TIMER(OMP_idle);
581 kmp_team_t *team = this_thr->th.th_team;
582 if (team && team->t.t_cancel_request == cancel_parallel)
596 if (task_team && KMP_HIDDEN_HELPER_WORKER_THREAD(th_gtid) &&
597 !TCR_4(__kmp_hidden_helper_team_done)) {
600 if (KMP_ATOMIC_LD_ACQ(&__kmp_unexecuted_hidden_helper_tasks) == 0) {
601 __kmp_hidden_helper_worker_thread_wait();
607 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
608 __kmp_pause_status != kmp_soft_paused)
612 if ((task_team != NULL) && TCR_4(task_team->tt.tt_found_tasks))
617 if (TCR_4(__kmp_global.g.g_time.dt.t_value) < hibernate)
620 if (KMP_BLOCKING(hibernate_goal, poll_count++))
628 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
629 __kmp_pause_status != kmp_soft_paused)
632 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
633 if (__kmp_mwait_enabled || __kmp_umwait_enabled) {
634 KF_TRACE(50, (
"__kmp_wait_sleep: T#%d using monitor/mwait\n", th_gtid));
635 flag->mwait(th_gtid);
638 KF_TRACE(50, (
"__kmp_wait_sleep: T#%d suspend time reached\n", th_gtid));
641 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
false);
643 flag->suspend(th_gtid);
646 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
true);
648 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
652 if (TCR_4(__kmp_global.g.g_done)) {
653 if (__kmp_global.g.g_abort)
654 __kmp_abort_thread();
656 }
else if (__kmp_tasking_mode != tskm_immediate_exec &&
657 this_thr->th.th_reap_state == KMP_SAFE_TO_REAP) {
658 this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
664 ompt_state_t ompt_exit_state = this_thr->th.ompt_thread_info.state;
665 if (ompt_enabled.enabled && ompt_exit_state != ompt_state_undefined) {
668 __ompt_implicit_task_end(this_thr, ompt_exit_state, tId);
669 ompt_exit_state = this_thr->th.ompt_thread_info.state;
672 if (ompt_exit_state == ompt_state_idle) {
673 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
677 #if KMP_STATS_ENABLED
679 if (KMP_GET_THREAD_STATE() == IDLE) {
680 KMP_POP_PARTITIONED_TIMER();
681 KMP_SET_THREAD_STATE(thread_state);
682 this_thr->th.th_stats->resetIdleFlag();
688 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
false);
690 KMP_FSYNC_SPIN_ACQUIRED(CCAST(
void *, spin));
692 kmp_team_t *team = this_thr->th.th_team;
693 if (team && team->t.t_cancel_request == cancel_parallel) {
694 if (tasks_completed) {
697 kmp_task_team_t *task_team = this_thr->th.th_task_team;
698 std::atomic<kmp_int32> *unfinished_threads =
699 &(task_team->tt.tt_unfinished_threads);
700 KMP_ATOMIC_INC(unfinished_threads);
708 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
712 static inline void __kmp_mwait_template(
int th_gtid, C *flag) {
713 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_mwait);
714 kmp_info_t *th = __kmp_threads[th_gtid];
716 KF_TRACE(30, (
"__kmp_mwait_template: T#%d enter for flag = %p\n", th_gtid,
720 KMP_DEBUG_ASSERT(__kmp_mwait_enabled || __kmp_umwait_enabled);
722 __kmp_suspend_initialize_thread(th);
723 __kmp_lock_suspend_mx(th);
725 volatile void *spin = flag->get();
726 void *cacheline = (
void *)(kmp_uintptr_t(spin) & ~(CACHE_LINE - 1));
728 if (!flag->done_check()) {
730 th->th.th_active = FALSE;
731 if (th->th.th_active_in_pool) {
732 th->th.th_active_in_pool = FALSE;
733 KMP_ATOMIC_DEC(&__kmp_thread_pool_active_nth);
734 KMP_DEBUG_ASSERT(TCR_4(__kmp_thread_pool_active_nth) >= 0);
736 flag->set_sleeping();
737 KF_TRACE(50, (
"__kmp_mwait_template: T#%d calling monitor\n", th_gtid));
739 if (__kmp_umwait_enabled) {
740 __kmp_umonitor(cacheline);
743 if (__kmp_mwait_enabled) {
744 __kmp_mm_monitor(cacheline, 0, 0);
750 if (flag->done_check())
751 flag->unset_sleeping();
754 TCW_PTR(th->th.th_sleep_loc, (
void *)flag);
755 th->th.th_sleep_loc_type = flag->get_type();
756 __kmp_unlock_suspend_mx(th);
757 KF_TRACE(50, (
"__kmp_mwait_template: T#%d calling mwait\n", th_gtid));
759 if (__kmp_umwait_enabled) {
760 __kmp_umwait(1, 100);
763 if (__kmp_mwait_enabled) {
764 __kmp_mm_mwait(0, __kmp_mwait_hints);
767 KF_TRACE(50, (
"__kmp_mwait_template: T#%d mwait done\n", th_gtid));
768 __kmp_lock_suspend_mx(th);
770 if (flag->is_sleeping())
771 flag->unset_sleeping();
772 TCW_PTR(th->th.th_sleep_loc, NULL);
773 th->th.th_sleep_loc_type = flag_unset;
776 th->th.th_active = TRUE;
777 if (TCR_4(th->th.th_in_pool)) {
778 KMP_ATOMIC_INC(&__kmp_thread_pool_active_nth);
779 th->th.th_active_in_pool = TRUE;
782 __kmp_unlock_suspend_mx(th);
783 KF_TRACE(30, (
"__kmp_mwait_template: T#%d exit\n", th_gtid));
791 template <
class C>
static inline void __kmp_release_template(C *flag) {
793 int gtid = TCR_4(__kmp_init_gtid) ? __kmp_get_gtid() : -1;
795 KF_TRACE(20, (
"__kmp_release: T#%d releasing flag(%x)\n", gtid, flag->get()));
796 KMP_DEBUG_ASSERT(flag->get());
797 KMP_FSYNC_RELEASING(flag->get_void_p());
799 flag->internal_release();
801 KF_TRACE(100, (
"__kmp_release: T#%d set new spin=%d\n", gtid, flag->get(),
804 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
807 if (flag->is_any_sleeping()) {
808 for (
unsigned int i = 0; i < flag->get_num_waiters(); ++i) {
810 kmp_info_t *waiter = flag->get_waiter(i);
812 int wait_gtid = waiter->th.th_info.ds.ds_gtid;
814 KF_TRACE(50, (
"__kmp_release: T#%d waking up thread T#%d since sleep "
816 gtid, wait_gtid, flag->get()));
817 flag->resume(wait_gtid);
824 template <
bool Cancellable,
bool Sleepable>
825 class kmp_flag_32 :
public kmp_flag_atomic<kmp_uint32, flag32, Sleepable> {
827 kmp_flag_32(std::atomic<kmp_uint32> *p)
829 kmp_flag_32(std::atomic<kmp_uint32> *p, kmp_info_t *thr)
831 kmp_flag_32(std::atomic<kmp_uint32> *p, kmp_uint32 c)
833 void suspend(
int th_gtid) { __kmp_suspend_32(th_gtid,
this); }
834 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
835 void mwait(
int th_gtid) { __kmp_mwait_32(th_gtid,
this); }
837 void resume(
int th_gtid) { __kmp_resume_32(th_gtid,
this); }
838 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid,
int final_spin,
839 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
840 kmp_int32 is_constrained) {
841 return __kmp_execute_tasks_32(
842 this_thr, gtid,
this, final_spin,
843 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
845 bool wait(kmp_info_t *this_thr,
846 int final_spin USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
848 return __kmp_wait_template<kmp_flag_32, TRUE, Cancellable, Sleepable>(
849 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
851 return __kmp_wait_template<kmp_flag_32, FALSE, Cancellable, Sleepable>(
852 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
854 void release() { __kmp_release_template(
this); }
855 flag_type get_ptr_type() {
return flag32; }
858 template <
bool Cancellable,
bool Sleepable>
859 class kmp_flag_64 :
public kmp_flag_native<kmp_uint64, flag64, Sleepable> {
861 kmp_flag_64(
volatile kmp_uint64 *p)
863 kmp_flag_64(
volatile kmp_uint64 *p, kmp_info_t *thr)
865 kmp_flag_64(
volatile kmp_uint64 *p, kmp_uint64 c)
867 kmp_flag_64(
volatile kmp_uint64 *p, kmp_uint64 c, std::atomic<bool> *loc)
869 void suspend(
int th_gtid) { __kmp_suspend_64(th_gtid,
this); }
870 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
871 void mwait(
int th_gtid) { __kmp_mwait_64(th_gtid,
this); }
873 void resume(
int th_gtid) { __kmp_resume_64(th_gtid,
this); }
874 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid,
int final_spin,
875 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
876 kmp_int32 is_constrained) {
877 return __kmp_execute_tasks_64(
878 this_thr, gtid,
this, final_spin,
879 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
881 bool wait(kmp_info_t *this_thr,
882 int final_spin USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
884 return __kmp_wait_template<kmp_flag_64, TRUE, Cancellable, Sleepable>(
885 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
887 return __kmp_wait_template<kmp_flag_64, FALSE, Cancellable, Sleepable>(
888 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
890 void release() { __kmp_release_template(
this); }
891 flag_type get_ptr_type() {
return flag64; }
894 template <
bool Cancellable,
bool Sleepable>
895 class kmp_atomic_flag_64
898 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p)
900 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p, kmp_info_t *thr)
902 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p, kmp_uint64 c)
904 kmp_atomic_flag_64(std::atomic<kmp_uint64> *p, kmp_uint64 c,
905 std::atomic<bool> *loc)
907 void suspend(
int th_gtid) { __kmp_atomic_suspend_64(th_gtid,
this); }
908 void mwait(
int th_gtid) { __kmp_atomic_mwait_64(th_gtid,
this); }
909 void resume(
int th_gtid) { __kmp_atomic_resume_64(th_gtid,
this); }
910 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid,
int final_spin,
911 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
912 kmp_int32 is_constrained) {
913 return __kmp_atomic_execute_tasks_64(
914 this_thr, gtid,
this, final_spin,
915 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
917 bool wait(kmp_info_t *this_thr,
918 int final_spin USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
920 return __kmp_wait_template<kmp_atomic_flag_64, TRUE, Cancellable,
922 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
924 return __kmp_wait_template<kmp_atomic_flag_64, FALSE, Cancellable,
926 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
928 void release() { __kmp_release_template(
this); }
929 flag_type get_ptr_type() {
return atomic_flag64; }
933 class kmp_flag_oncore :
public kmp_flag_native<kmp_uint64, flag_oncore, false> {
936 enum barrier_type bt;
937 kmp_info_t *this_thr;
941 unsigned char &byteref(
volatile kmp_uint64 *loc,
size_t offset) {
942 return (RCAST(
unsigned char *, CCAST(kmp_uint64 *, loc)))[offset];
946 kmp_flag_oncore(
volatile kmp_uint64 *p)
947 :
kmp_flag_native<kmp_uint64, flag_oncore, false>(p), flag_switch(false) {
949 kmp_flag_oncore(
volatile kmp_uint64 *p, kmp_uint32 idx)
952 bt(bs_last_barrier) USE_ITT_BUILD_ARG(itt_sync_obj(nullptr)) {}
953 kmp_flag_oncore(
volatile kmp_uint64 *p, kmp_uint64 c, kmp_uint32 idx,
954 enum barrier_type bar_t,
955 kmp_info_t *thr USE_ITT_BUILD_ARG(
void *itt))
957 flag_switch(false), bt(bar_t),
958 this_thr(thr) USE_ITT_BUILD_ARG(itt_sync_obj(itt)) {}
959 virtual ~kmp_flag_oncore()
override {}
960 void *
operator new(
size_t size) {
return __kmp_allocate(size); }
961 void operator delete(
void *p) { __kmp_free(p); }
963 return byteref(&old_loc, offset) ==
checker;
968 if (this_thr->th.th_bar[bt].bb.wait_flag == KMP_BARRIER_SWITCH_TO_OWN_FLAG)
970 if (byteref(get(), offset) != 1 && !flag_switch)
972 else if (flag_switch) {
973 this_thr->th.th_bar[bt].bb.wait_flag = KMP_BARRIER_SWITCHING;
974 kmp_flag_64<> flag(&this_thr->th.th_bar[bt].bb.b_go,
975 (kmp_uint64)KMP_BARRIER_STATE_BUMP);
976 __kmp_wait_64(this_thr, &flag, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
982 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME) {
983 byteref(get(), offset) = 1;
986 byteref(&mask, offset) = 1;
987 KMP_TEST_THEN_OR64(get(), mask);
990 void wait(kmp_info_t *this_thr,
int final_spin) {
992 __kmp_wait_template<kmp_flag_oncore, TRUE>(
993 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
995 __kmp_wait_template<kmp_flag_oncore, FALSE>(
996 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
998 void release() { __kmp_release_template(
this); }
999 void suspend(
int th_gtid) { __kmp_suspend_oncore(th_gtid,
this); }
1000 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT
1001 void mwait(
int th_gtid) { __kmp_mwait_oncore(th_gtid,
this); }
1003 void resume(
int th_gtid) { __kmp_resume_oncore(th_gtid,
this); }
1004 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid,
int final_spin,
1005 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
1006 kmp_int32 is_constrained) {
1008 int ret = __kmp_execute_tasks_oncore(
1009 this_thr, gtid,
this, final_spin,
1010 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
1011 if (ompd_state & OMPD_ENABLE_BP)
1015 return __kmp_execute_tasks_oncore(
1016 this_thr, gtid,
this, final_spin,
1017 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
1020 enum barrier_type get_bt() {
return bt; }
1021 flag_type get_ptr_type() {
return flag_oncore; }
1024 static inline void __kmp_null_resume_wrapper(kmp_info_t *thr) {
1025 int gtid = __kmp_gtid_from_thread(thr);
1026 void *flag = CCAST(
void *, thr->th.th_sleep_loc);
1027 flag_type type = thr->th.th_sleep_loc_type;
1033 __kmp_resume_32(gtid, RCAST(kmp_flag_32<> *, flag));
1036 __kmp_resume_64(gtid, RCAST(kmp_flag_64<> *, flag));
1039 __kmp_atomic_resume_64(gtid, RCAST(kmp_atomic_flag_64<> *, flag));
1042 __kmp_resume_oncore(gtid, RCAST(kmp_flag_oncore *, flag));
1046 KF_TRACE(100, (
"__kmp_null_resume_wrapper: flag type %d is unset\n", type));
1049 KF_TRACE(100, (
"__kmp_null_resume_wrapper: flag type %d does not match any "
1050 "known flag type\n",
std::atomic< PtrType > * loc
bool is_sleeping_val(PtrType old_loc)
bool done_check_val(PtrType old_loc)
void set(std::atomic< PtrType > *new_loc)
std::atomic< PtrType > * get()
bool is_sleeping_val(PtrType old_loc)
virtual bool notdone_check()
virtual bool done_check_val(PtrType old_loc)
virtual bool done_check()
kmp_uint32 num_waiting_threads
kmp_info_t * waiting_threads[1]
kmp_uint32 get_num_waiters()
kmp_info_t * get_waiter(kmp_uint32 i)
void set_waiter(kmp_info_t *thr)
stats_state_e
the states which a thread can be in