15 #ifndef KMP_TASKDEPS_H 16 #define KMP_TASKDEPS_H 22 #define KMP_ACQUIRE_DEPNODE(gtid, n) __kmp_acquire_lock(&(n)->dn.lock, (gtid)) 23 #define KMP_RELEASE_DEPNODE(gtid, n) __kmp_release_lock(&(n)->dn.lock, (gtid)) 25 static inline void __kmp_node_deref(kmp_info_t *thread, kmp_depnode_t *node) {
29 kmp_int32 n = KMP_ATOMIC_DEC(&node->dn.nrefs) - 1;
31 KMP_ASSERT(node->dn.nrefs == 0);
33 __kmp_fast_free(thread, node);
35 __kmp_thread_free(thread, node);
40 static inline void __kmp_depnode_list_free(kmp_info_t *thread,
41 kmp_depnode_list *list) {
42 kmp_depnode_list *next;
44 for (; list; list = next) {
47 __kmp_node_deref(thread, list->node);
49 __kmp_fast_free(thread, list);
51 __kmp_thread_free(thread, list);
56 static inline void __kmp_dephash_free_entries(kmp_info_t *thread,
58 for (
size_t i = 0; i < h->size; i++) {
60 kmp_dephash_entry_t *next;
61 for (kmp_dephash_entry_t *entry = h->buckets[i]; entry; entry = next) {
62 next = entry->next_in_bucket;
63 __kmp_depnode_list_free(thread, entry->last_ins);
64 __kmp_depnode_list_free(thread, entry->last_mtxs);
65 __kmp_node_deref(thread, entry->last_out);
66 if (entry->mtx_lock) {
67 __kmp_destroy_lock(entry->mtx_lock);
68 __kmp_free(entry->mtx_lock);
71 __kmp_fast_free(thread, entry);
73 __kmp_thread_free(thread, entry);
81 static inline void __kmp_dephash_free(kmp_info_t *thread, kmp_dephash_t *h) {
82 __kmp_dephash_free_entries(thread, h);
84 __kmp_fast_free(thread, h);
86 __kmp_thread_free(thread, h);
90 static inline void __kmp_release_deps(kmp_int32 gtid, kmp_taskdata_t *task) {
91 kmp_info_t *thread = __kmp_threads[gtid];
92 kmp_depnode_t *node = task->td_depnode;
94 if (task->td_dephash) {
96 40, (
"__kmp_release_deps: T#%d freeing dependencies hash of task %p.\n",
98 __kmp_dephash_free(thread, task->td_dephash);
99 task->td_dephash = NULL;
105 KA_TRACE(20, (
"__kmp_release_deps: T#%d notifying successors of task %p.\n",
108 KMP_ACQUIRE_DEPNODE(gtid, node);
111 KMP_RELEASE_DEPNODE(gtid, node);
113 kmp_depnode_list_t *next;
114 for (kmp_depnode_list_t *p = node->dn.successors; p; p = next) {
115 kmp_depnode_t *successor = p->node;
116 kmp_int32 npredecessors = KMP_ATOMIC_DEC(&successor->dn.npredecessors) - 1;
120 if (npredecessors == 0) {
122 if (successor->dn.task) {
123 KA_TRACE(20, (
"__kmp_release_deps: T#%d successor %p of %p scheduled " 125 gtid, successor->dn.task, task));
126 __kmp_omp_task(gtid, successor->dn.task,
false);
131 __kmp_node_deref(thread, p->node);
133 __kmp_fast_free(thread, p);
135 __kmp_thread_free(thread, p);
139 __kmp_node_deref(thread, node);
143 (
"__kmp_release_deps: T#%d all successors of %p notified of completion\n",
147 #endif // OMP_40_ENABLED 149 #endif // KMP_TASKDEPS_H