18#define KMP_ACQUIRE_DEPNODE(gtid, n) __kmp_acquire_lock(&(n)->dn.lock, (gtid))
19#define KMP_RELEASE_DEPNODE(gtid, n) __kmp_release_lock(&(n)->dn.lock, (gtid))
21static inline void __kmp_node_deref(kmp_info_t *thread, kmp_depnode_t *node) {
25 kmp_int32 n = KMP_ATOMIC_DEC(&node->dn.nrefs) - 1;
26 KMP_DEBUG_ASSERT(n >= 0);
28 KMP_ASSERT(node->dn.nrefs == 0);
30 __kmp_fast_free(thread, node);
32 __kmp_thread_free(thread, node);
37static inline void __kmp_depnode_list_free(kmp_info_t *thread,
38 kmp_depnode_list *list) {
39 kmp_depnode_list *next;
41 for (; list; list = next) {
44 __kmp_node_deref(thread, list->node);
46 __kmp_fast_free(thread, list);
48 __kmp_thread_free(thread, list);
53static inline void __kmp_dephash_free_entries(kmp_info_t *thread,
55 for (
size_t i = 0; i < h->size; i++) {
57 kmp_dephash_entry_t *next;
58 for (kmp_dephash_entry_t *entry = h->buckets[i]; entry; entry = next) {
59 next = entry->next_in_bucket;
60 __kmp_depnode_list_free(thread, entry->last_set);
61 __kmp_depnode_list_free(thread, entry->prev_set);
62 __kmp_node_deref(thread, entry->last_out);
63 if (entry->mtx_lock) {
64 __kmp_destroy_lock(entry->mtx_lock);
65 __kmp_free(entry->mtx_lock);
68 __kmp_fast_free(thread, entry);
70 __kmp_thread_free(thread, entry);
76 __kmp_node_deref(thread, h->last_all);
80static inline void __kmp_dephash_free(kmp_info_t *thread, kmp_dephash_t *h) {
81 __kmp_dephash_free_entries(thread, h);
83 __kmp_fast_free(thread, h);
85 __kmp_thread_free(thread, h);
89extern void __kmpc_give_task(kmp_task_t *ptask, kmp_int32 start);
91static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
92 kmp_info_t *thread = __kmp_threads[gtid];
93 kmp_depnode_t *node = task->td_depnode;
96 if (UNLIKELY(node && (node->dn.mtx_num_locks < 0))) {
98 node->dn.mtx_num_locks = -node->dn.mtx_num_locks;
99 for (
int i = node->dn.mtx_num_locks - 1; i >= 0; --i) {
100 KMP_DEBUG_ASSERT(node->dn.mtx_locks[i] != NULL);
101 __kmp_release_lock(node->dn.mtx_locks[i], gtid);
105 if (task->td_dephash) {
107 40, (
"__kmp_release_deps: T#%d freeing dependencies hash of task %p.\n",
109 __kmp_dephash_free(thread, task->td_dephash);
110 task->td_dephash = NULL;
116 KA_TRACE(20, (
"__kmp_release_deps: T#%d notifying successors of task %p.\n",
119 KMP_ACQUIRE_DEPNODE(gtid, node);
122 KMP_RELEASE_DEPNODE(gtid, node);
124 kmp_depnode_list_t *next;
125 kmp_taskdata_t *next_taskdata;
126 for (kmp_depnode_list_t *p = node->dn.successors; p; p = next) {
127 kmp_depnode_t *successor = p->node;
128 kmp_int32 npredecessors = KMP_ATOMIC_DEC(&successor->dn.npredecessors) - 1;
132 if (npredecessors == 0) {
134 if (successor->dn.task) {
135 KA_TRACE(20, (
"__kmp_release_deps: T#%d successor %p of %p scheduled "
137 gtid, successor->dn.task, task));
141 if (KMP_HIDDEN_HELPER_THREAD(gtid)) {
143 KMP_ASSERT(task->td_flags.hidden_helper);
144 next_taskdata = KMP_TASK_TO_TASKDATA(successor->dn.task);
148 if (!next_taskdata->td_flags.hidden_helper) {
149 kmp_int32 encountering_gtid =
150 next_taskdata->td_alloc_thread->th.th_info.ds.ds_gtid;
151 kmp_int32 encountering_tid = __kmp_tid_from_gtid(encountering_gtid);
152 __kmpc_give_task(successor->dn.task, encountering_tid);
154 __kmp_omp_task(gtid, successor->dn.task,
false);
157 __kmp_omp_task(gtid, successor->dn.task,
false);
163 __kmp_node_deref(thread, p->node);
165 __kmp_fast_free(thread, p);
167 __kmp_thread_free(thread, p);
171 __kmp_node_deref(thread, node);
175 (
"__kmp_release_deps: T#%d all successors of %p notified of completion\n",