aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorMatias Elo <matias.elo@nokia.com>2020-08-03 09:58:32 +0300
committerPetri Savolainen <petri.savolainen@nokia.com>2020-08-25 10:58:12 +0300
commitbc7693c8b678a915fa7859bf8f0c99cca61ee021 (patch)
tree19978a837cb228b7364ed00c006b2ced8fcca3ac /example
parentaccc89eb28992d77d6ad46e65a3154b4221d0b0d (diff)
example: ipsec: fix premature application exit
Previously, the application would close right away if no test streams were created. A signal handler is added to close the application cleanly. Fixes: https://github.com/OpenDataPlane/odp/issues/983 Signed-off-by: Matias Elo <matias.elo@nokia.com> Reviewed-by: Janne Peltonen <janne.peltonen@nokia.com>
Diffstat (limited to 'example')
-rw-r--r--example/ipsec/odp_ipsec.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 2db4c9158..e382bc0e5 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <getopt.h>
+#include <signal.h>
#include <unistd.h>
#include <inttypes.h>
@@ -96,7 +97,8 @@ typedef struct {
odp_barrier_t sync_barrier;
odp_queue_t poll_queues[MAX_POLL_QUEUES];
int num_polled_queues;
- volatile int stop_workers;
+ /* Stop workers if set to 1 */
+ odp_atomic_u32_t exit_threads;
} global_data_t;
/* helper funcs */
@@ -183,6 +185,13 @@ typedef struct {
static global_data_t *global;
+static void sig_handler(int signo ODP_UNUSED)
+{
+ if (global == NULL)
+ return;
+ odp_atomic_store_u32(&global->exit_threads, 1);
+}
+
/**
* Get per packet processing context from packet buffer
*
@@ -1052,7 +1061,7 @@ int pktio_thread(void *arg ODP_UNUSED)
odp_barrier_wait(&global->sync_barrier);
/* Loop packets */
- while (global->stop_workers == 0) {
+ while (!odp_atomic_load_u32(&global->exit_threads)) {
pkt_disposition_e rc;
pkt_ctx_t *ctx;
odp_queue_t dispatchq;
@@ -1223,6 +1232,10 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ /* Signal handler has to be registered before global init in case ODP
+ * implementation creates internal threads/processes. */
+ signal(SIGINT, sig_handler);
+
odp_init_param_init(&init_param);
init_param.mem_model = helper_options.mem_model;
@@ -1255,6 +1268,7 @@ main(int argc, char *argv[])
}
memset(global, 0, sizeof(global_data_t));
global->shm = shm;
+ odp_atomic_init_u32(&global->exit_threads, 0);
/* Configure scheduler */
odp_schedule_config(NULL);
@@ -1342,22 +1356,18 @@ main(int argc, char *argv[])
thr_params.instance = instance;
odph_odpthreads_create(thread_tbl, &cpumask, &thr_params);
- /*
- * If there are streams attempt to verify them else
- * wait indefinitely
- */
+ /* If there are streams attempt to verify them. Otherwise, run until
+ * SIGINT is received. */
if (stream_count) {
odp_bool_t done;
+
do {
done = verify_stream_db_outputs();
sleep(1);
} while (!done);
printf("All received\n");
+ odp_atomic_store_u32(&global->exit_threads, 1);
}
-
- global->stop_workers = 1;
- odp_mb_full();
-
odph_odpthreads_join(thread_tbl);
/* Stop and close used pktio devices */