aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorJere Leppänen <jere.leppanen@nokia.com>2021-08-10 15:41:53 +0300
committerPetri Savolainen <petri.savolainen@nokia.com>2021-09-30 11:10:11 +0300
commit84c474392f411a72185a9b62b82778fd30a36c3e (patch)
tree350dbe8617644dde2523bad337a7758f2dc68323 /helper
parentaa6f29c285abfdadd77bb3a8a14a63b9ef6ec81b (diff)
helper: threads: add synchronized thread creation timeout parameter
Add a parameter to odph_thread_common_param_t, which allows specifying the time to wait for the synchronization signal in synchronized thread creation. Signed-off-by: Jere Leppänen <jere.leppanen@nokia.com> Reviewed-by: Matias Elo <matias.elo@nokia.com>
Diffstat (limited to 'helper')
-rw-r--r--helper/include/odp/helper/threads.h13
-rw-r--r--helper/threads.c7
2 files changed, 19 insertions, 1 deletions
diff --git a/helper/include/odp/helper/threads.h b/helper/include/odp/helper/threads.h
index fe3118918..983537f9d 100644
--- a/helper/include/odp/helper/threads.h
+++ b/helper/include/odp/helper/threads.h
@@ -165,6 +165,19 @@ typedef struct {
int sync;
/**
+ * Synchronized thread creation timeout in nanoseconds
+ *
+ * When synchronized thread creation has been requested, waiting for the
+ * synchronization signal times out once the time indicated by this
+ * parameter has passed.
+ *
+ * If this parameter is 0, the default value is used.
+ *
+ * Default value is ODP_TIME_SEC_IN_NS.
+ */
+ uint64_t sync_timeout;
+
+ /**
* Thread parameter sharing
*
* 0: Thread parameters are not shared. The thread parameter table
diff --git a/helper/threads.c b/helper/threads.c
index d18f08284..181ea66eb 100644
--- a/helper/threads.c
+++ b/helper/threads.c
@@ -232,6 +232,7 @@ void odph_thread_param_init(odph_thread_param_t *param)
void odph_thread_common_param_init(odph_thread_common_param_t *param)
{
memset(param, 0, sizeof(*param));
+ param->sync_timeout = ODP_TIME_SEC_IN_NS;
}
int odph_thread_create(odph_thread_t thread[],
@@ -296,6 +297,10 @@ int odph_thread_create(odph_thread_t thread[],
uint32_t status;
int timeout = 0;
odp_atomic_u32_t *atomic = &start_args->status;
+ uint64_t timeout_ns = param->sync_timeout;
+
+ if (!timeout_ns)
+ timeout_ns = ODP_TIME_SEC_IN_NS;
t1 = odp_time_local();
@@ -303,7 +308,7 @@ int odph_thread_create(odph_thread_t thread[],
odp_cpu_pause();
t2 = odp_time_local();
diff_ns = odp_time_diff_ns(t2, t1);
- timeout = diff_ns > ODP_TIME_SEC_IN_NS;
+ timeout = diff_ns > timeout_ns;
status = odp_atomic_load_acq_u32(atomic);
} while (status != INIT_DONE && timeout == 0);