diff options
author | Janne Peltonen <janne.peltonen@nokia.com> | 2022-06-08 16:27:05 +0300 |
---|---|---|
committer | Petri Savolainen <petri.savolainen@nokia.com> | 2022-07-07 09:25:04 +0300 |
commit | 04a9a2ca48fb405f955ecbf5967f268ef96302af (patch) | |
tree | 9bd264f9f7851af7cbf5cd540895c5a7b213dc6d /test | |
parent | a8428f86d81d1a9fb2b9604afa8fe33ff69fc315 (diff) |
test: cunit: do not start new threads if old ones are still running
odp_cunit_thread_create() is not supposed to be called twice without
calling odp_cunit_thread_join() in between. This is because internal
thread state is kept in the static thread_tbl variable. Enforce the
restriction by failing thread creation if odp_cunit_thread_join()
has not been called for the previous set of threads.
Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/common/odp_cunit_common.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/common/odp_cunit_common.c b/test/common/odp_cunit_common.c index b458dbda9..ebde4710a 100644 --- a/test/common/odp_cunit_common.c +++ b/test/common/odp_cunit_common.c @@ -29,6 +29,7 @@ /* Globals */ static int allow_skip_result; static odph_thread_t thread_tbl[MAX_WORKERS]; +static int threads_running; static odp_instance_t instance; static char *progname; @@ -52,6 +53,12 @@ int odp_cunit_thread_create(int num, int func_ptr(void *), void *const arg[], in odph_thread_common_param_t thr_common; odph_thread_param_t thr_param[num]; + if (threads_running) { + /* thread_tbl is already in use */ + fprintf(stderr, "error: %s: threads already running\n", __func__); + return -1; + } + odph_thread_common_param_init(&thr_common); if (arg == NULL) @@ -84,6 +91,8 @@ int odp_cunit_thread_create(int num, int func_ptr(void *), void *const arg[], in if (ret != num) fprintf(stderr, "error: odph_thread_create() failed.\n"); + threads_running = (ret > 0); + return ret; } @@ -94,6 +103,7 @@ int odp_cunit_thread_join(int num) fprintf(stderr, "error: odph_thread_join() failed.\n"); return -1; } + threads_running = 0; return 0; } |