embb_counter_t* embb_thread_index_counter() { int compare_to = 0; if (embb_atomic_load_int(&embb_thread_index_counter_flag) != 2) { if (embb_atomic_compare_and_swap_int( &embb_thread_index_counter_flag, &compare_to, 1)) { embb_counter_init(&embb_thread_index_counter_index); embb_atomic_store_int(&embb_thread_index_counter_flag, 2); } while (embb_atomic_load_int(&embb_thread_index_counter_flag) != 2) {} } return &embb_thread_index_counter_index; }
/** * \pre the calling thread is the only active thread * * \post the thread indices count and calling thread index is reset */ void embb_internal_thread_index_reset() { /** This function is only called in tests, usually when all other threads * except the main thread have terminated. However, the main thread still has * potentially stored its old index value in its thread local storage, * which might be assigned additionally to another thread (as the counter is * reset), which may lead to hard to detect bugs. Therefore, reset the thread * local thread id here. */ embb_internal_thread_index_var = UINT_MAX; embb_counter_init(embb_thread_index_counter()); }
void embb_internal_thread_index_reset() { embb_counter_init(embb_thread_index_counter()); }