27 ABTD_ATOMIC_UINT32_STATIC_INITIALIZER(0);
94 ABTI_CHECK_ERROR(abt_errno);
143 ABTI_UB_ASSERT(ABTI_initialized());
150 ABTI_CHECK_ERROR(abt_errno);
198 int abt_errno, init_stage = 0;
200 ABTI_global *p_global;
201 ABTI_xstream *p_local_xstream;
203 abt_errno =
ABTU_malloc(
sizeof(ABTI_global), (
void **)&p_global);
204 ABTI_CHECK_ERROR(abt_errno);
205 ABTI_global_set_global(p_global);
208 ABTD_env_init(p_global);
211 abt_errno = ABTI_mem_init(p_global);
217 ABTI_thread_reset_id();
218 ABTI_sched_reset_id();
219 ABTI_pool_reset_id();
221 #ifndef ABT_CONFIG_DISABLE_TOOL_INTERFACE
223 ABTD_spinlock_clear(&p_global->tool_writer_lock);
224 p_global->tool_thread_cb_f = NULL;
225 p_global->tool_thread_user_arg = NULL;
226 ABTD_atomic_relaxed_store_uint64(&p_global->tool_thread_event_mask_tagged,
230 ABTI_unit_init_hash_table(p_global);
233 p_global->p_xstream_head = NULL;
234 p_global->num_xstreams = 0;
237 ABTD_spinlock_clear(&p_global->xstream_list_lock);
240 abt_errno = ABTI_xstream_create_primary(p_global, &p_local_xstream);
246 ABTI_local_set_xstream(p_local_xstream);
249 ABTI_ythread *p_primary_ythread;
251 ABTI_ythread_create_primary(p_global,
252 ABTI_xstream_get_local(p_local_xstream),
253 p_local_xstream, &p_primary_ythread);
259 ABTD_atomic_relaxed_store_int(&p_primary_ythread->thread.state,
261 p_primary_ythread->thread.p_last_xstream = p_local_xstream;
262 p_global->p_primary_ythread = p_primary_ythread;
263 p_local_xstream->p_thread = &p_primary_ythread->thread;
266 ABTI_xstream_start_primary(p_global, &p_local_xstream, p_local_xstream,
269 if (p_global->print_config ==
ABT_TRUE) {
270 ABTI_info_print_config(p_global, stdout);
275 if (init_stage >= 2) {
276 ABTI_xstream_free(p_global, ABTI_xstream_get_local(p_local_xstream),
278 ABTI_local_set_xstream(NULL);
280 if (init_stage >= 1) {
281 ABTI_mem_finalize(p_global);
283 ABTD_affinity_finalize(p_global);
285 ABTI_global_set_global(NULL);
286 ABTI_HANDLE_ERROR(abt_errno);
291 ABTI_local *p_local = ABTI_local_get_local();
300 ABTI_global *p_global = ABTI_global_get_global();
301 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream_or_null(p_local);
303 ABTI_CHECK_TRUE(!ABTI_IS_EXT_THREAD_ENABLED || p_local_xstream,
306 ABTI_CHECK_TRUE_MSG(p_local_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY,
308 "ABT_finalize must be called by the primary ES.");
310 ABTI_thread *p_self = p_local_xstream->p_thread;
311 ABTI_CHECK_TRUE_MSG(p_self->type & ABTI_THREAD_TYPE_PRIMARY,
313 "ABT_finalize must be called by the primary ULT.");
314 ABTI_ythread *p_ythread;
317 #ifndef ABT_CONFIG_DISABLE_TOOL_INTERFACE
319 ABTI_tool_event_thread_update_callback(p_global, NULL,
324 ABTI_sched_finish(p_local_xstream->p_main_sched);
328 ABTI_ythread_yield_orphan(&p_local_xstream, p_ythread,
330 ABTI_ASSERT(p_local_xstream == ABTI_local_get_xstream(p_local));
331 ABTI_ASSERT(p_local_xstream->p_thread == p_self);
334 p_local_xstream->p_thread = NULL;
335 ABTI_ythread_free_primary(p_global, ABTI_xstream_get_local(p_local_xstream),
339 ABTI_xstream_free(p_global, ABTI_xstream_get_local(p_local_xstream),
343 ABTI_local_set_xstream(NULL);
346 ABTI_ASSERT(p_global->p_xstream_head == NULL);
349 ABTI_mem_finalize(p_global);
352 ABTD_affinity_finalize(p_global);
355 ABTI_unit_finalize_hash_table(p_global);
359 ABTI_global_set_global(NULL);