13 #ifndef KMP_WAIT_RELEASE_H 14 #define KMP_WAIT_RELEASE_H 18 #include "kmp_stats.h" 20 #include "ompt-specific.h" 45 struct flag_properties {
46 unsigned int type : 16;
47 unsigned int reserved : 16;
60 : loc(p), t({(
short unsigned int)ft, 0U}) {}
61 volatile P *
get() {
return loc; }
62 void *get_void_p() {
return RCAST(
void *, CCAST(P *, loc)); }
63 void set(
volatile P *new_loc) { loc = new_loc; }
65 P load() {
return *loc; }
66 void store(P val) { *loc = val; }
80 : loc(p), t({(
short unsigned int)ft, 0U}) {}
84 std::atomic<P> *
get() {
return loc; }
92 void set(std::atomic<P> *new_loc) { loc = new_loc; }
100 P
load() {
return loc->load(std::memory_order_acquire); }
104 void store(P val) { loc->store(val, std::memory_order_release); }
130 static void __ompt_implicit_task_end(kmp_info_t *this_thr,
131 ompt_state_t ompt_state,
133 int ds_tid = this_thr->th.th_info.ds.ds_tid;
134 if (ompt_state == ompt_state_wait_barrier_implicit) {
135 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
137 void *codeptr = NULL;
138 if (ompt_enabled.ompt_callback_sync_region_wait) {
139 ompt_callbacks.ompt_callback(ompt_callback_sync_region_wait)(
140 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
143 if (ompt_enabled.ompt_callback_sync_region) {
144 ompt_callbacks.ompt_callback(ompt_callback_sync_region)(
145 ompt_sync_region_barrier_implicit, ompt_scope_end, NULL, tId,
149 if (!KMP_MASTER_TID(ds_tid)) {
150 if (ompt_enabled.ompt_callback_implicit_task) {
151 int flags = this_thr->th.ompt_thread_info.parallel_flags;
152 flags = (flags & ompt_parallel_league) ? ompt_task_initial
153 : ompt_task_implicit;
154 ompt_callbacks.ompt_callback(ompt_callback_implicit_task)(
155 ompt_scope_end, NULL, tId, 0, ds_tid, flags);
158 this_thr->th.ompt_thread_info.state = ompt_state_idle;
160 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
171 template <
class C,
bool final_spin,
bool Cancellable =
false,
172 bool Sleepable =
true>
174 __kmp_wait_template(kmp_info_t *this_thr,
175 C *flag USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
176 #if USE_ITT_BUILD && USE_ITT_NOTIFY 177 volatile void *spin = flag->get();
181 int tasks_completed = FALSE;
183 kmp_uint64 poll_count;
184 kmp_uint64 hibernate_goal;
186 kmp_uint32 hibernate;
189 KMP_FSYNC_SPIN_INIT(spin, NULL);
190 if (flag->done_check()) {
191 KMP_FSYNC_SPIN_ACQUIRED(CCAST(
void *, spin));
194 th_gtid = this_thr->th.th_info.ds.ds_gtid;
196 kmp_team_t *team = this_thr->th.th_team;
197 if (team && team->t.t_cancel_request == cancel_parallel)
202 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
true);
205 (
"__kmp_wait_sleep: T#%d waiting for flag(%p)\n", th_gtid, flag));
206 #if KMP_STATS_ENABLED 261 ompt_state_t ompt_entry_state;
263 if (ompt_enabled.enabled) {
264 ompt_entry_state = this_thr->th.ompt_thread_info.state;
265 if (!final_spin || ompt_entry_state != ompt_state_wait_barrier_implicit ||
266 KMP_MASTER_TID(this_thr->th.th_info.ds.ds_tid)) {
267 ompt_lw_taskteam_t *team =
268 this_thr->th.th_team->t.ompt_serialized_team_info;
270 tId = &(team->ompt_task_info.task_data);
272 tId = OMPT_CUR_TASK_DATA(this_thr);
275 tId = &(this_thr->th.ompt_thread_info.task_data);
277 if (final_spin && (__kmp_tasking_mode == tskm_immediate_exec ||
278 this_thr->th.th_task_team == NULL)) {
280 __ompt_implicit_task_end(this_thr, ompt_entry_state, tId);
285 KMP_INIT_YIELD(spins);
287 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME ||
288 __kmp_pause_status == kmp_soft_paused) {
292 #ifdef KMP_ADJUST_BLOCKTIME 293 if (__kmp_pause_status == kmp_soft_paused ||
294 (__kmp_zero_bt && !this_thr->th.th_team_bt_set))
299 hibernate = this_thr->th.th_team_bt_intervals;
301 hibernate = this_thr->th.th_team_bt_intervals;
312 hibernate += TCR_4(__kmp_global.g.g_time.dt.t_value);
313 KF_TRACE(20, (
"__kmp_wait_sleep: T#%d now=%d, hibernate=%d, intervals=%d\n",
314 th_gtid, __kmp_global.g.g_time.dt.t_value, hibernate,
315 hibernate - __kmp_global.g.g_time.dt.t_value));
317 if (__kmp_pause_status == kmp_soft_paused) {
319 hibernate_goal = KMP_NOW();
321 hibernate_goal = KMP_NOW() + this_thr->th.th_team_bt_intervals;
324 #endif // KMP_USE_MONITOR 330 while (flag->notdone_check()) {
331 kmp_task_team_t *task_team = NULL;
332 if (__kmp_tasking_mode != tskm_immediate_exec) {
333 task_team = this_thr->th.th_task_team;
341 if (task_team != NULL) {
342 if (TCR_SYNC_4(task_team->tt.tt_active)) {
343 if (KMP_TASKING_ENABLED(task_team))
345 this_thr, th_gtid, final_spin,
346 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj), 0);
348 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
350 KMP_DEBUG_ASSERT(!KMP_MASTER_TID(this_thr->th.th_info.ds.ds_tid));
353 if (final_spin && ompt_enabled.enabled)
354 __ompt_implicit_task_end(this_thr, ompt_entry_state, tId);
356 this_thr->th.th_task_team = NULL;
357 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
360 this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;
364 KMP_FSYNC_SPIN_PREPARE(CCAST(
void *, spin));
365 if (TCR_4(__kmp_global.g.g_done)) {
366 if (__kmp_global.g.g_abort)
367 __kmp_abort_thread();
373 KMP_YIELD_OVERSUB_ELSE_SPIN(spins);
375 #if KMP_STATS_ENABLED 378 if (this_thr->th.th_stats->isIdle() &&
379 KMP_GET_THREAD_STATE() == FORK_JOIN_BARRIER) {
380 KMP_SET_THREAD_STATE(IDLE);
381 KMP_PUSH_PARTITIONED_TIMER(OMP_idle);
386 kmp_team_t *team = this_thr->th.th_team;
387 if (team && team->t.t_cancel_request == cancel_parallel)
401 if (task_team && KMP_HIDDEN_HELPER_WORKER_THREAD(th_gtid) &&
402 !TCR_4(__kmp_hidden_helper_team_done)) {
405 if (KMP_ATOMIC_LD_ACQ(&__kmp_unexecuted_hidden_helper_tasks) == 0) {
406 __kmp_hidden_helper_worker_thread_wait();
412 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
413 __kmp_pause_status != kmp_soft_paused)
417 if ((task_team != NULL) && TCR_4(task_team->tt.tt_found_tasks))
422 if (TCR_4(__kmp_global.g.g_time.dt.t_value) < hibernate)
425 if (KMP_BLOCKING(hibernate_goal, poll_count++))
433 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME &&
434 __kmp_pause_status != kmp_soft_paused)
437 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 438 if (__kmp_mwait_enabled || __kmp_umwait_enabled) {
439 KF_TRACE(50, (
"__kmp_wait_sleep: T#%d using monitor/mwait\n", th_gtid));
440 flag->mwait(th_gtid);
443 KF_TRACE(50, (
"__kmp_wait_sleep: T#%d suspend time reached\n", th_gtid));
446 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
false);
448 flag->suspend(th_gtid);
451 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
true);
453 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 457 if (TCR_4(__kmp_global.g.g_done)) {
458 if (__kmp_global.g.g_abort)
459 __kmp_abort_thread();
461 }
else if (__kmp_tasking_mode != tskm_immediate_exec &&
462 this_thr->th.th_reap_state == KMP_SAFE_TO_REAP) {
463 this_thr->th.th_reap_state = KMP_NOT_SAFE_TO_REAP;
469 ompt_state_t ompt_exit_state = this_thr->th.ompt_thread_info.state;
470 if (ompt_enabled.enabled && ompt_exit_state != ompt_state_undefined) {
473 __ompt_implicit_task_end(this_thr, ompt_exit_state, tId);
474 ompt_exit_state = this_thr->th.ompt_thread_info.state;
477 if (ompt_exit_state == ompt_state_idle) {
478 this_thr->th.ompt_thread_info.state = ompt_state_overhead;
482 #if KMP_STATS_ENABLED 484 if (KMP_GET_THREAD_STATE() == IDLE) {
485 KMP_POP_PARTITIONED_TIMER();
486 KMP_SET_THREAD_STATE(thread_state);
487 this_thr->th.th_stats->resetIdleFlag();
493 KMP_ATOMIC_ST_REL(&this_thr->th.th_blocking,
false);
495 KMP_FSYNC_SPIN_ACQUIRED(CCAST(
void *, spin));
497 kmp_team_t *team = this_thr->th.th_team;
498 if (team && team->t.t_cancel_request == cancel_parallel) {
499 if (tasks_completed) {
502 kmp_task_team_t *task_team = this_thr->th.th_task_team;
503 std::atomic<kmp_int32> *unfinished_threads =
504 &(task_team->tt.tt_unfinished_threads);
505 KMP_ATOMIC_INC(unfinished_threads);
513 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 517 static inline void __kmp_mwait_template(
int th_gtid, C *flag) {
518 KMP_TIME_DEVELOPER_PARTITIONED_BLOCK(USER_mwait);
519 kmp_info_t *th = __kmp_threads[th_gtid];
521 KF_TRACE(30, (
"__kmp_mwait_template: T#%d enter for flag = %p\n", th_gtid,
525 KMP_DEBUG_ASSERT(__kmp_mwait_enabled || __kmp_umwait_enabled);
527 __kmp_suspend_initialize_thread(th);
528 __kmp_lock_suspend_mx(th);
530 volatile void *spin = flag->get();
531 void *cacheline = (
void *)(kmp_uintptr_t(spin) & ~(CACHE_LINE - 1));
533 if (!flag->done_check()) {
535 th->th.th_active = FALSE;
536 if (th->th.th_active_in_pool) {
537 th->th.th_active_in_pool = FALSE;
538 KMP_ATOMIC_DEC(&__kmp_thread_pool_active_nth);
539 KMP_DEBUG_ASSERT(TCR_4(__kmp_thread_pool_active_nth) >= 0);
541 flag->set_sleeping();
542 KF_TRACE(50, (
"__kmp_mwait_template: T#%d calling monitor\n", th_gtid));
544 if (__kmp_umwait_enabled) {
545 __kmp_umonitor(cacheline);
548 if (__kmp_mwait_enabled) {
549 __kmp_mm_monitor(cacheline, 0, 0);
555 if (flag->done_check())
556 flag->unset_sleeping();
559 TCW_PTR(th->th.th_sleep_loc, (
void *)flag);
560 __kmp_unlock_suspend_mx(th);
561 KF_TRACE(50, (
"__kmp_mwait_template: T#%d calling mwait\n", th_gtid));
563 if (__kmp_umwait_enabled) {
564 __kmp_umwait(1, 100);
567 if (__kmp_mwait_enabled) {
568 __kmp_mm_mwait(0, __kmp_mwait_hints);
571 KF_TRACE(50, (
"__kmp_mwait_template: T#%d mwait done\n", th_gtid));
572 __kmp_lock_suspend_mx(th);
574 if (flag->is_sleeping())
575 flag->unset_sleeping();
576 TCW_PTR(th->th.th_sleep_loc, NULL);
579 th->th.th_active = TRUE;
580 if (TCR_4(th->th.th_in_pool)) {
581 KMP_ATOMIC_INC(&__kmp_thread_pool_active_nth);
582 th->th.th_active_in_pool = TRUE;
585 __kmp_unlock_suspend_mx(th);
586 KF_TRACE(30, (
"__kmp_mwait_template: T#%d exit\n", th_gtid));
588 #endif // KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 594 template <
class C>
static inline void __kmp_release_template(C *flag) {
596 int gtid = TCR_4(__kmp_init_gtid) ? __kmp_get_gtid() : -1;
598 KF_TRACE(20, (
"__kmp_release: T#%d releasing flag(%x)\n", gtid, flag->get()));
599 KMP_DEBUG_ASSERT(flag->get());
600 KMP_FSYNC_RELEASING(flag->get_void_p());
602 flag->internal_release();
604 KF_TRACE(100, (
"__kmp_release: T#%d set new spin=%d\n", gtid, flag->get(),
607 if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
610 if (flag->is_any_sleeping()) {
611 for (
unsigned int i = 0; i < flag->get_num_waiters(); ++i) {
613 kmp_info_t *waiter = flag->get_waiter(i);
615 int wait_gtid = waiter->th.th_info.ds.ds_gtid;
617 KF_TRACE(50, (
"__kmp_release: T#%d waking up thread T#%d since sleep " 619 gtid, wait_gtid, flag->get()));
620 flag->resume(wait_gtid);
627 template <
typename FlagType>
struct flag_traits {};
629 template <>
struct flag_traits<kmp_uint32> {
630 typedef kmp_uint32 flag_t;
632 static inline flag_t tcr(flag_t f) {
return TCR_4(f); }
633 static inline flag_t test_then_add4(
volatile flag_t *f) {
634 return KMP_TEST_THEN_ADD4_32(RCAST(
volatile kmp_int32 *, f));
636 static inline flag_t test_then_or(
volatile flag_t *f, flag_t v) {
637 return KMP_TEST_THEN_OR32(f, v);
639 static inline flag_t test_then_and(
volatile flag_t *f, flag_t v) {
640 return KMP_TEST_THEN_AND32(f, v);
644 template <>
struct flag_traits<kmp_uint64> {
645 typedef kmp_uint64 flag_t;
647 static inline flag_t tcr(flag_t f) {
return TCR_8(f); }
648 static inline flag_t test_then_add4(
volatile flag_t *f) {
649 return KMP_TEST_THEN_ADD4_64(RCAST(
volatile kmp_int64 *, f));
651 static inline flag_t test_then_or(
volatile flag_t *f, flag_t v) {
652 return KMP_TEST_THEN_OR64(f, v);
654 static inline flag_t test_then_and(
volatile flag_t *f, flag_t v) {
655 return KMP_TEST_THEN_AND64(f, v);
660 template <
typename FlagType,
bool Sleepable>
662 typedef flag_traits<FlagType> traits_type;
670 kmp_basic_flag_native(
volatile FlagType *p)
672 kmp_basic_flag_native(
volatile FlagType *p, kmp_info_t *thr)
674 waiting_threads[0] = thr;
676 kmp_basic_flag_native(
volatile FlagType *p, FlagType c)
678 num_waiting_threads(0) {}
683 kmp_info_t *get_waiter(kmp_uint32 i) {
684 KMP_DEBUG_ASSERT(i < num_waiting_threads);
685 return waiting_threads[i];
690 kmp_uint32 get_num_waiters() {
return num_waiting_threads; }
696 void set_waiter(kmp_info_t *thr) {
697 waiting_threads[0] = thr;
698 num_waiting_threads = 1;
705 return (traits_type::tcr(*(this->
get())) & ~KMP_BARRIER_SLEEP_STATE) ==
708 return traits_type::tcr(*(this->
get())) == checker;
714 bool done_check_val(FlagType old_loc) {
return old_loc == checker; }
722 bool notdone_check() {
return traits_type::tcr(*(this->
get())) != checker; }
727 void internal_release() {
728 (void)traits_type::test_then_add4((
volatile FlagType *)this->
get());
735 FlagType set_sleeping() {
736 return traits_type::test_then_or((
volatile FlagType *)this->
get(),
737 KMP_BARRIER_SLEEP_STATE);
744 FlagType unset_sleeping() {
745 return traits_type::test_then_and((
volatile FlagType *)this->
get(),
746 ~KMP_BARRIER_SLEEP_STATE);
752 bool is_sleeping_val(FlagType old_loc) {
753 return old_loc & KMP_BARRIER_SLEEP_STATE;
758 bool is_sleeping() {
return is_sleeping_val(*(this->
get())); }
759 bool is_any_sleeping() {
return is_sleeping_val(*(this->
get())); }
760 kmp_uint8 *get_stolen() {
return NULL; }
761 enum barrier_type get_bt() {
return bs_last_barrier; }
764 template <
typename FlagType,
bool Sleepable>
765 class kmp_basic_flag :
public kmp_flag<FlagType> {
766 typedef flag_traits<FlagType> traits_type;
774 kmp_basic_flag(std::atomic<FlagType> *p)
776 kmp_basic_flag(std::atomic<FlagType> *p, kmp_info_t *thr)
778 waiting_threads[0] = thr;
780 kmp_basic_flag(std::atomic<FlagType> *p, FlagType c)
782 num_waiting_threads(0) {}
787 kmp_info_t *get_waiter(kmp_uint32 i) {
788 KMP_DEBUG_ASSERT(i < num_waiting_threads);
789 return waiting_threads[i];
794 kmp_uint32 get_num_waiters() {
return num_waiting_threads; }
800 void set_waiter(kmp_info_t *thr) {
801 waiting_threads[0] = thr;
802 num_waiting_threads = 1;
809 return (this->load() & ~KMP_BARRIER_SLEEP_STATE) == checker;
811 return this->load() == checker;
817 bool done_check_val(FlagType old_loc) {
return old_loc == checker; }
825 bool notdone_check() {
return this->load() != checker; }
830 void internal_release() { KMP_ATOMIC_ADD(this->
get(), 4); }
836 FlagType set_sleeping() {
837 return KMP_ATOMIC_OR(this->
get(), KMP_BARRIER_SLEEP_STATE);
844 FlagType unset_sleeping() {
845 return KMP_ATOMIC_AND(this->
get(), ~KMP_BARRIER_SLEEP_STATE);
851 bool is_sleeping_val(FlagType old_loc) {
852 return old_loc & KMP_BARRIER_SLEEP_STATE;
857 bool is_sleeping() {
return is_sleeping_val(this->load()); }
858 bool is_any_sleeping() {
return is_sleeping_val(this->load()); }
859 kmp_uint8 *get_stolen() {
return NULL; }
860 enum barrier_type get_bt() {
return bs_last_barrier; }
863 template <
bool Cancellable,
bool Sleepable>
864 class kmp_flag_32 :
public kmp_basic_flag<kmp_uint32, Sleepable> {
866 kmp_flag_32(std::atomic<kmp_uint32> *p)
867 : kmp_basic_flag<kmp_uint32, Sleepable>(p) {}
868 kmp_flag_32(std::atomic<kmp_uint32> *p, kmp_info_t *thr)
869 : kmp_basic_flag<kmp_uint32, Sleepable>(p, thr) {}
870 kmp_flag_32(std::atomic<kmp_uint32> *p, kmp_uint32 c)
871 : kmp_basic_flag<kmp_uint32, Sleepable>(p, c) {}
872 void suspend(
int th_gtid) { __kmp_suspend_32(th_gtid,
this); }
873 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 874 void mwait(
int th_gtid) { __kmp_mwait_32(th_gtid,
this); }
876 void resume(
int th_gtid) { __kmp_resume_32(th_gtid,
this); }
877 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid,
int final_spin,
878 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
879 kmp_int32 is_constrained) {
880 return __kmp_execute_tasks_32(
881 this_thr, gtid,
this, final_spin,
882 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
884 bool wait(kmp_info_t *this_thr,
885 int final_spin USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
887 return __kmp_wait_template<kmp_flag_32, TRUE, Cancellable, Sleepable>(
888 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
890 return __kmp_wait_template<kmp_flag_32, FALSE, Cancellable, Sleepable>(
891 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
893 void release() { __kmp_release_template(
this); }
897 template <
bool Cancellable,
bool Sleepable>
898 class kmp_flag_64 :
public kmp_basic_flag_native<kmp_uint64, Sleepable> {
900 kmp_flag_64(
volatile kmp_uint64 *p)
901 : kmp_basic_flag_native<kmp_uint64, Sleepable>(p) {}
902 kmp_flag_64(
volatile kmp_uint64 *p, kmp_info_t *thr)
903 : kmp_basic_flag_native<kmp_uint64, Sleepable>(p, thr) {}
904 kmp_flag_64(
volatile kmp_uint64 *p, kmp_uint64 c)
905 : kmp_basic_flag_native<kmp_uint64, Sleepable>(p, c) {}
906 void suspend(
int th_gtid) { __kmp_suspend_64(th_gtid,
this); }
907 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 908 void mwait(
int th_gtid) { __kmp_mwait_64(th_gtid,
this); }
910 void resume(
int th_gtid) { __kmp_resume_64(th_gtid,
this); }
911 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid,
int final_spin,
912 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
913 kmp_int32 is_constrained) {
914 return __kmp_execute_tasks_64(
915 this_thr, gtid,
this, final_spin,
916 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
918 bool wait(kmp_info_t *this_thr,
919 int final_spin USE_ITT_BUILD_ARG(
void *itt_sync_obj)) {
921 return __kmp_wait_template<kmp_flag_64, TRUE, Cancellable, Sleepable>(
922 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
924 return __kmp_wait_template<kmp_flag_64, FALSE, Cancellable, Sleepable>(
925 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
927 void release() { __kmp_release_template(
this); }
934 kmp_info_t *waiting_threads[1];
935 kmp_uint32 num_waiting_threads;
939 enum barrier_type bt;
940 kmp_info_t *this_thr;
946 unsigned char &byteref(
volatile kmp_uint64 *loc,
size_t offset) {
947 return (RCAST(
unsigned char *, CCAST(kmp_uint64 *, loc)))[offset];
951 kmp_flag_oncore(
volatile kmp_uint64 *p)
953 flag_switch(
false) {}
954 kmp_flag_oncore(
volatile kmp_uint64 *p, kmp_uint32 idx)
956 offset(idx), flag_switch(
false) {}
957 kmp_flag_oncore(
volatile kmp_uint64 *p, kmp_uint64 c, kmp_uint32 idx,
958 enum barrier_type bar_t,
959 kmp_info_t *thr USE_ITT_BUILD_ARG(
void *itt))
961 num_waiting_threads(0), offset(idx), flag_switch(
false), bt(bar_t),
962 this_thr(thr) USE_ITT_BUILD_ARG(itt_sync_obj(itt)) {}
963 kmp_info_t *get_waiter(kmp_uint32 i) {
964 KMP_DEBUG_ASSERT(i < num_waiting_threads);
965 return waiting_threads[i];
967 kmp_uint32 get_num_waiters() {
return num_waiting_threads; }
968 void set_waiter(kmp_info_t *thr) {
969 waiting_threads[0] = thr;
970 num_waiting_threads = 1;
972 bool done_check_val(kmp_uint64 old_loc) {
973 return byteref(&old_loc, offset) == checker;
975 bool done_check() {
return done_check_val(*
get()); }
976 bool notdone_check() {
978 if (this_thr->th.th_bar[bt].bb.wait_flag == KMP_BARRIER_SWITCH_TO_OWN_FLAG)
980 if (byteref(
get(), offset) != 1 && !flag_switch)
982 else if (flag_switch) {
983 this_thr->th.th_bar[bt].bb.wait_flag = KMP_BARRIER_SWITCHING;
984 kmp_flag_64<> flag(&this_thr->th.th_bar[bt].bb.b_go,
985 (kmp_uint64)KMP_BARRIER_STATE_BUMP);
986 __kmp_wait_64(this_thr, &flag, TRUE USE_ITT_BUILD_ARG(itt_sync_obj));
990 void internal_release() {
992 if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME) {
993 byteref(
get(), offset) = 1;
996 byteref(&mask, offset) = 1;
997 KMP_TEST_THEN_OR64(
get(), mask);
1000 kmp_uint64 set_sleeping() {
1001 return KMP_TEST_THEN_OR64(
get(), KMP_BARRIER_SLEEP_STATE);
1003 kmp_uint64 unset_sleeping() {
1004 return KMP_TEST_THEN_AND64(
get(), ~KMP_BARRIER_SLEEP_STATE);
1006 bool is_sleeping_val(kmp_uint64 old_loc) {
1007 return old_loc & KMP_BARRIER_SLEEP_STATE;
1009 bool is_sleeping() {
return is_sleeping_val(*
get()); }
1010 bool is_any_sleeping() {
return is_sleeping_val(*
get()); }
1011 void wait(kmp_info_t *this_thr,
int final_spin) {
1013 __kmp_wait_template<kmp_flag_oncore, TRUE>(
1014 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
1016 __kmp_wait_template<kmp_flag_oncore, FALSE>(
1017 this_thr,
this USE_ITT_BUILD_ARG(itt_sync_obj));
1019 void release() { __kmp_release_template(
this); }
1020 void suspend(
int th_gtid) { __kmp_suspend_oncore(th_gtid,
this); }
1021 #if KMP_HAVE_MWAIT || KMP_HAVE_UMWAIT 1022 void mwait(
int th_gtid) { __kmp_mwait_oncore(th_gtid,
this); }
1024 void resume(
int th_gtid) { __kmp_resume_oncore(th_gtid,
this); }
1025 int execute_tasks(kmp_info_t *this_thr, kmp_int32 gtid,
int final_spin,
1026 int *thread_finished USE_ITT_BUILD_ARG(
void *itt_sync_obj),
1027 kmp_int32 is_constrained) {
1029 int ret = __kmp_execute_tasks_oncore(
1030 this_thr, gtid,
this, final_spin,
1031 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
1032 if (ompd_state & OMPD_ENABLE_BP)
1036 return __kmp_execute_tasks_oncore(
1037 this_thr, gtid,
this, final_spin,
1038 thread_finished USE_ITT_BUILD_ARG(itt_sync_obj), is_constrained);
1041 kmp_uint8 *get_stolen() {
return NULL; }
1042 enum barrier_type get_bt() {
return bt; }
1048 static inline void __kmp_null_resume_wrapper(
int gtid,
volatile void *flag) {
1052 switch (RCAST(kmp_flag_64<> *, CCAST(
void *, flag))->get_type()) {
1054 __kmp_resume_32(gtid, (kmp_flag_32<> *)NULL);
1057 __kmp_resume_64(gtid, (kmp_flag_64<> *)NULL);
1060 __kmp_resume_oncore(gtid, (kmp_flag_oncore *)NULL);
1069 #endif // KMP_WAIT_RELEASE_H
stats_state_e
the states which a thread can be in