/** * Tries to return the next free (internal) thread index. * * An index is only set, if there was still one available. * * This function has local scope. * * \return EMBB_SUCCESS, if a free index was available. EMBB_ERROR otherwise. */ int embb_try_get_next_thread_index(unsigned int* free_index) { assert(free_index != NULL); unsigned int index = embb_counter_increment(embb_thread_index_counter()); if (index >= *embb_max_number_thread_indices()) { embb_counter_decrement(embb_thread_index_counter()); return EMBB_ERROR; } *free_index = index; return EMBB_SUCCESS; }
/** * \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()); }