@@ -23,6 +23,7 @@ int odp_system_info_init(void);
int odp_thread_init_global(void);
int odp_thread_init_local(void);
+int odp_thread_term_local(void);
int odp_shm_init_global(void);
int odp_shm_init_local(void);
@@ -90,6 +90,5 @@ int odp_init_local(void)
int odp_term_local(void)
{
- ODP_UNIMPLEMENTED();
- return 0;
+ return (odp_thread_term_local() > 0) ? 1 : 0;
}
@@ -43,9 +43,15 @@ static void *odp_run_start_routine(void *arg)
return NULL;
}
- void *ret = start_args->start_routine(start_args->arg);
+ void *ret_ptr = start_args->start_routine(start_args->arg);
_odp_flush_caches();
- return ret;
+ int ret = odp_term_local();
+ if (ret < 0)
+ ODP_ERR("Local term failed\n");
+ else if (ret == 0 && odp_term_global())
+ ODP_ERR("Global term failed\n");
+
+ return ret_ptr;
}
@@ -32,6 +32,7 @@ typedef struct {
typedef struct {
thread_state_t thr[ODP_CONFIG_MAX_THREADS];
odp_atomic_u32_t num;
+ odp_atomic_u32_t next_id;
} thread_globals_t;
@@ -58,6 +59,8 @@ int odp_thread_init_global(void)
return -1;
memset(thread_globals, 0, sizeof(thread_globals_t));
+ odp_atomic_init_u32(&thread_globals->next_id, 0);
+ odp_atomic_init_u32(&thread_globals->num, 0);
return 0;
}
@@ -67,12 +70,13 @@ static int thread_id(void)
uint32_t id;
int cpu;
- id = odp_atomic_fetch_inc_u32(&thread_globals->num);
+ id = odp_atomic_fetch_inc_u32(&thread_globals->next_id);
if (id >= ODP_CONFIG_MAX_THREADS) {
ODP_ERR("Too many threads\n");
return -1;
}
+ odp_atomic_inc_u32(&thread_globals->num);
cpu = sched_getcpu();
@@ -87,7 +91,6 @@ static int thread_id(void)
return id;
}
-
int odp_thread_init_local(void)
{
int id;
@@ -101,6 +104,13 @@ int odp_thread_init_local(void)
return 0;
}
+int odp_thread_term_local(void)
+{
+ uint32_t num;
+ num = odp_atomic_fetch_dec_u32(&thread_globals->num);
+ ODP_ASSERT(num > 0, "Number of threads should be > 0");
+ return num - 1; /* return a number of threads left */
+}
int odp_thread_id(void)
{
Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org> --- platform/linux-generic/include/odp_internal.h | 1 + platform/linux-generic/odp_init.c | 3 +-- platform/linux-generic/odp_linux.c | 10 ++++++++-- platform/linux-generic/odp_thread.c | 14 ++++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-)