6 #ifndef ABTI_XSTREAM_H_INCLUDED 7 #define ABTI_XSTREAM_H_INCLUDED 11 static inline ABTI_xstream *ABTI_xstream_get_ptr(
ABT_xstream xstream)
13 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK 14 ABTI_xstream *p_xstream;
18 p_xstream = (ABTI_xstream *)xstream;
22 return (ABTI_xstream *)xstream;
26 static inline ABT_xstream ABTI_xstream_get_handle(ABTI_xstream *p_xstream)
28 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK 30 if (p_xstream == NULL) {
41 static inline void ABTI_xstream_set_request(ABTI_xstream *p_xstream,
44 ABTD_atomic_fetch_or_uint32(&p_xstream->request, req);
47 static inline void ABTI_xstream_unset_request(ABTI_xstream *p_xstream,
50 ABTD_atomic_fetch_and_uint32(&p_xstream->request, ~req);
54 static inline ABTI_sched *ABTI_xstream_get_top_sched(ABTI_xstream *p_xstream)
56 return p_xstream->scheds[p_xstream->num_scheds - 1];
60 static inline ABTI_sched *ABTI_xstream_get_parent_sched(ABTI_xstream *p_xstream)
62 ABTI_ASSERT(p_xstream->num_scheds >= 2);
63 return p_xstream->scheds[p_xstream->num_scheds - 2];
67 static inline ABTD_thread_context *
68 ABTI_xstream_get_sched_ctx(ABTI_xstream *p_xstream)
70 ABTI_sched *p_sched = ABTI_xstream_get_top_sched(p_xstream);
71 return p_sched->p_ctx;
75 static inline void ABTI_xstream_pop_sched(ABTI_xstream *p_xstream)
77 p_xstream->num_scheds--;
78 ABTI_ASSERT(p_xstream->num_scheds >= 0);
83 static inline void ABTI_xstream_replace_top_sched(ABTI_xstream *p_xstream,
86 p_xstream->scheds[p_xstream->num_scheds - 1] = p_sched;
90 static inline void ABTI_xstream_push_sched(ABTI_xstream *p_xstream,
93 if (p_xstream->num_scheds == p_xstream->max_scheds) {
94 int cur_size = p_xstream->max_scheds;
95 int new_size = cur_size + 10;
97 temp =
ABTU_realloc(p_xstream->scheds, cur_size *
sizeof(ABTI_sched *),
98 new_size *
sizeof(ABTI_sched *));
99 p_xstream->scheds = (ABTI_sched **)temp;
100 p_xstream->max_scheds = new_size;
103 p_xstream->scheds[p_xstream->num_scheds++] = p_sched;
107 static inline ABTI_pool *ABTI_xstream_get_main_pool(ABTI_xstream *p_xstream)
109 ABT_pool pool = p_xstream->p_main_sched->pools[0];
110 return ABTI_pool_get_ptr(pool);
113 static inline void ABTI_xstream_terminate_thread(ABTI_local *p_local,
114 ABTI_thread *p_thread)
116 LOG_EVENT(
"[U%" PRIu64
":E%d] terminated\n", ABTI_thread_get_id(p_thread),
117 p_thread->p_last_xstream->rank);
118 if (p_thread->refcount == 0) {
119 ABTD_atomic_release_store_int(&p_thread->state,
121 ABTI_thread_free(p_local, p_thread);
122 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 123 }
else if (p_thread->is_sched) {
125 ABTD_atomic_release_store_int(&p_thread->state,
127 ABTI_sched_discard_and_free(p_local, p_thread->is_sched);
134 ABTD_atomic_release_store_int(&p_thread->state,
139 static inline void ABTI_xstream_terminate_task(ABTI_local *p_local,
142 LOG_EVENT(
"[T%" PRIu64
":E%d] terminated\n", ABTI_task_get_id(p_task),
143 p_task->p_xstream->rank);
144 if (p_task->refcount == 0) {
145 ABTD_atomic_release_store_int(&p_task->state,
147 ABTI_task_free(p_local, p_task);
148 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 149 }
else if (p_task->is_sched) {
151 ABTD_atomic_release_store_int(&p_task->state,
153 ABTI_sched_discard_and_free(p_local, p_task->is_sched);
160 ABTD_atomic_release_store_int(&p_task->state,
166 static inline ABTI_native_thread_id
167 ABTI_xstream_get_native_thread_id(ABTI_xstream *p_xstream)
169 return (ABTI_native_thread_id)p_xstream;
struct ABT_xstream_opaque * ABT_xstream
struct ABT_pool_opaque * ABT_pool
static void * ABTU_realloc(void *ptr, size_t old_size, size_t new_size)
#define LOG_EVENT(fmt,...)