aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@nokia.com>2023-11-24 10:44:14 +0200
committerPetri Savolainen <petri.savolainen@nokia.com>2023-12-19 18:23:59 +0200
commitfda9ee7d2f7e0b43f8e188dc8c5be28958dbd1bc (patch)
tree65279b3ede6f5a9c1b59a95c962f2186294f03db /example
parent05b146f8bb080f715c5bdba1417fbcfbdabd875e (diff)
api: timer: only inactive timers can be freed
Remove possibility to free a timer that is running. When timer free call returns, the timer handle cannot be referenced any more. Expiration and event delivery of an already destroyed timer is an error prone corner case. Signed-off-by: Petri Savolainen <petri.savolainen@nokia.com> Reviewed-by: Jere Leppänen <jere.leppanen@nokia.com> Acked-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
Diffstat (limited to 'example')
-rw-r--r--example/debug/odp_debug.c17
-rw-r--r--example/timer/odp_timer_accuracy.c9
-rw-r--r--example/timer/odp_timer_simple.c18
3 files changed, 28 insertions, 16 deletions
diff --git a/example/debug/odp_debug.c b/example/debug/odp_debug.c
index 06d10f34d..cca6fa939 100644
--- a/example/debug/odp_debug.c
+++ b/example/debug/odp_debug.c
@@ -384,6 +384,7 @@ static int timer_debug(void)
uint64_t tick;
uint64_t max_tmo = ODP_TIME_SEC_IN_NS;
uint64_t res = 100 * ODP_TIME_MSEC_IN_NS;
+ int started = 0;
odp_pool_param_init(&pool_param);
pool_param.type = ODP_POOL_TIMEOUT;
@@ -462,16 +463,17 @@ static int timer_debug(void)
start_param.tick = tick;
start_param.tmo_ev = event;
- if (odp_timer_start(timer, &start_param) != ODP_TIMER_SUCCESS)
+ if (odp_timer_start(timer, &start_param) == ODP_TIMER_SUCCESS)
+ started = 1;
+ else
ODPH_ERR("Timer start failed.\n");
printf("\n");
odp_timer_print(timer);
- event = odp_timer_free(timer);
-
- if (event == ODP_EVENT_INVALID) {
- ODPH_ERR("Timer free failed.\n");
+ if (started && odp_timer_cancel(timer, &event) != ODP_TIMER_SUCCESS) {
+ ODPH_ERR("Timer cancel failed\n");
+ return -1;
} else {
timeout = odp_timeout_from_event(event);
@@ -481,6 +483,11 @@ static int timer_debug(void)
odp_timeout_free(timeout);
}
+ if (odp_timer_free(timer)) {
+ ODPH_ERR("Timer free failed\n");
+ return -1;
+ }
+
odp_timer_pool_destroy(timer_pool);
if (odp_queue_destroy(queue)) {
diff --git a/example/timer/odp_timer_accuracy.c b/example/timer/odp_timer_accuracy.c
index 05e4e9181..83ca371d9 100644
--- a/example/timer/odp_timer_accuracy.c
+++ b/example/timer/odp_timer_accuracy.c
@@ -806,7 +806,6 @@ static int destroy_timers(test_global_t *test_global)
{
uint64_t i, alloc_timers;
odp_timer_t timer;
- odp_event_t ev;
int ret = 0;
alloc_timers = test_global->opt.alloc_timers;
@@ -817,10 +816,10 @@ static int destroy_timers(test_global_t *test_global)
if (timer == ODP_TIMER_INVALID)
break;
- ev = odp_timer_free(timer);
-
- if (ev != ODP_EVENT_INVALID)
- odp_event_free(ev);
+ if (odp_timer_free(timer)) {
+ printf("Timer free failed: %" PRIu64 "\n", i);
+ ret = -1;
+ }
}
if (test_global->timer_pool != ODP_TIMER_POOL_INVALID)
diff --git a/example/timer/odp_timer_simple.c b/example/timer/odp_timer_simple.c
index fdf38c9d3..b1c818c76 100644
--- a/example/timer/odp_timer_simple.c
+++ b/example/timer/odp_timer_simple.c
@@ -159,18 +159,24 @@ int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED)
}
/* Destroy created resources */
- rc += odp_timer_cancel(tim, &ev);
- rc += -(odp_timer_free(tim) == ODP_EVENT_INVALID);
odp_event_free(ev);
- ret += odp_queue_destroy(queue);
+ if (odp_timer_free(tim))
+ ret++;
+
+ if (odp_queue_destroy(queue))
+ ret++;
err:
odp_timer_pool_destroy(timer_pool);
err_tp:
- ret += odp_pool_destroy(timeout_pool);
- ret += odp_term_local();
+ if (odp_pool_destroy(timeout_pool))
+ ret++;
+
+ if (odp_term_local())
+ ret++;
err_local:
- ret += odp_term_global(instance);
+ if (odp_term_global(instance))
+ ret++;
err_global:
return ret;
}