Lines Matching +full:free +full:- +full:running

5  * SPDX-License-Identifier: Apache-2.0
26 * For SOCs with several micro-controllers (AMP) one instance of this module
41 * Which thread is running is controlled using {cond|mtx}_threads and
100 bool running; /* Is this the currently running thread */ member
140 tt_el->thead_cnt, in abort_tail()
144 tt_el->running = false; in abort_tail()
145 tt_el->state = ABORTED; in abort_tail()
161 tt_el->running = false; in nct_wait_until_allowed()
164 tt_el->thead_cnt, in nct_wait_until_allowed()
168 while (this_th_nbr != this->currently_allowed_thread) { in nct_wait_until_allowed()
169 pthread_cond_wait(&this->cond_threads, &this->mtx_threads); in nct_wait_until_allowed()
171 if (tt_el->state == ABORTING) { in nct_wait_until_allowed()
176 tt_el->running = true; in nct_wait_until_allowed()
179 tt_el->thead_cnt, in nct_wait_until_allowed()
196 tt_el->thead_cnt, in nct_let_run()
200 this->currently_allowed_thread = next_allowed_th; in nct_let_run()
209 NSI_SAFE_CALL(pthread_cond_broadcast(&this->cond_threads)); in nct_let_run()
220 NSI_SAFE_CALL(pthread_mutex_unlock(&this->mtx_threads)); in nct_exit_and_cleanup()
246 int this_th_nbr = this->currently_allowed_thread; in nct_swap_threads()
250 if (this_th_nbr == -1) { /* This is the first time a thread was swapped in */ in nct_swap_threads()
258 if (tt_el->state == ABORTING) { in nct_swap_threads()
260 tt_el->thead_cnt, in nct_swap_threads()
296 struct te_status_t *this = element->ts_status; in nct_cleanup_handler()
305 if (!this->terminate) { in nct_cleanup_handler()
310 element->thread_idx, in nct_cleanup_handler()
314 NSI_SAFE_CALL(pthread_mutex_unlock(&this->mtx_threads)); in nct_cleanup_handler()
328 struct te_status_t *this = tt_el->ts_status; in nct_thread_starter()
330 int thread_idx = tt_el->thread_idx; in nct_thread_starter()
333 tt_el->thead_cnt, in nct_thread_starter()
338 * We block until all other running threads reach the while loop in nct_thread_starter()
341 NSI_SAFE_CALL(pthread_mutex_lock(&this->mtx_threads)); in nct_thread_starter()
347 if (!this->threads_table || this->terminate) { in nct_thread_starter()
356 tt_el->thead_cnt, in nct_thread_starter()
366 this->fptr(tt_el->payload); in nct_thread_starter()
374 tt_el->thead_cnt, in nct_thread_starter()
378 tt_el->running = false; in nct_thread_starter()
379 tt_el->state = FAILED; in nct_thread_starter()
389 struct threads_table_el *threads_table = this->threads_table; in ttable_get_element()
391 if (index >= this->threads_table_size) { /* LCOV_EXCL_BR_LINE */ in ttable_get_element()
394 index, this->threads_table_size); /* LCOV_EXCL_LINE */ in ttable_get_element()
397 index -= NCT_ALLOC_CHUNK_SIZE; in ttable_get_element()
398 threads_table = threads_table[NCT_ALLOC_CHUNK_SIZE - 1].next; in ttable_get_element()
404 * Return the first free entry index in the threads table
408 struct threads_table_el *tt_el = this->threads_table; in ttable_get_empty_slot()
410 for (int i = 0; i < this->threads_table_size; i++, tt_el = tt_el->next) { in ttable_get_empty_slot()
411 if ((tt_el->state == NOTUSED) in ttable_get_empty_slot()
413 && (tt_el->state == ABORTED))) { in ttable_get_empty_slot()
431 tt_el = ttable_get_element(this, this->threads_table_size-1); in ttable_get_empty_slot()
432 tt_el->next = new_chunk; in ttable_get_empty_slot()
434 this->threads_table_size += NCT_ALLOC_CHUNK_SIZE; in ttable_get_empty_slot()
437 for (int i = 0 ; i < NCT_ALLOC_CHUNK_SIZE - 1; i++) { in ttable_get_empty_slot()
440 new_chunk[NCT_ALLOC_CHUNK_SIZE - 1].next = NULL; in ttable_get_empty_slot()
443 return this->threads_table_size - NCT_ALLOC_CHUNK_SIZE; in ttable_get_empty_slot()
469 tt_el->state = USED; in nct_new_thread()
470 tt_el->running = false; in nct_new_thread()
471 tt_el->thead_cnt = this->thread_create_count++; in nct_new_thread()
472 tt_el->payload = payload; in nct_new_thread()
473 tt_el->ts_status = this; in nct_new_thread()
474 tt_el->thread_idx = t_slot; in nct_new_thread()
476 NSI_SAFE_CALL(pthread_create(&tt_el->thread, in nct_new_thread()
483 tt_el->thead_cnt, in nct_new_thread()
485 tt_el->thread); in nct_new_thread()
506 * Note: This (and the calloc below) won't be free'd by this code in nct_init()
517 this->fptr = fptr; in nct_init()
518 this->thread_create_count = 0; in nct_init()
519 this->currently_allowed_thread = -1; in nct_init()
521 NSI_SAFE_CALL(pthread_cond_init(&this->cond_threads, NULL)); in nct_init()
522 NSI_SAFE_CALL(pthread_mutex_init(&this->mtx_threads, NULL)); in nct_init()
524 this->threads_table = calloc(NCT_ALLOC_CHUNK_SIZE, in nct_init()
526 if (this->threads_table == NULL) { /* LCOV_EXCL_BR_LINE */ in nct_init()
530 this->threads_table_size = NCT_ALLOC_CHUNK_SIZE; in nct_init()
532 for (int i = 0 ; i < NCT_ALLOC_CHUNK_SIZE - 1; i++) { in nct_init()
533 this->threads_table[i].next = &this->threads_table[i+1]; in nct_init()
535 this->threads_table[NCT_ALLOC_CHUNK_SIZE - 1].next = NULL; in nct_init()
537 NSI_SAFE_CALL(pthread_mutex_lock(&this->mtx_threads)); in nct_init()
543 * Free any allocated memory by the threading emulator and clean up.
559 if (!this || !this->threads_table) { /* LCOV_EXCL_BR_LINE */ in nct_clean_up()
563 this->terminate = true; in nct_clean_up()
566 struct threads_table_el *tt_el = this->threads_table; in nct_clean_up()
568 for (int i = 0; i < this->threads_table_size; i++, tt_el = tt_el->next) { in nct_clean_up()
569 if (tt_el->state != USED) { in nct_clean_up()
574 if (pthread_cancel(tt_el->thread)) { in nct_clean_up()
585 * free(this->threads_table); in nct_clean_up()
587 * this->threads_table = NULL; in nct_clean_up()
589 * (void)pthread_cond_destroy(&this->cond_threads); in nct_clean_up()
590 * (void)pthread_mutex_destroy(&this->mtx_threads); in nct_clean_up()
592 * free(this); in nct_clean_up()
602 * If it is marking another thread, at some non-specific time in the future
612 if (thread_idx == this->currently_allowed_thread) { in nct_abort_thread()
615 tt_el->thead_cnt, in nct_abort_thread()
619 if (tt_el->state != USED) { /* LCOV_EXCL_BR_LINE */ in nct_abort_thread()
625 tt_el->thead_cnt, in nct_abort_thread()
628 tt_el->state = ABORTING; in nct_abort_thread()
649 return tt_el->thead_cnt; in nct_get_unique_thread_id()
657 return pthread_setname_np(tt_el->thread, str); in nct_thread_name_set()
675 * But part of the pre-initialization during creation of a new thread
689 * non-typical code paths.
710 * free'd memory, and therefore a segfault.