aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorMatias Elo <matias.elo@nokia.com>2020-08-03 10:14:06 +0300
committerPetri Savolainen <petri.savolainen@nokia.com>2020-08-25 10:58:12 +0300
commit63956d0a67056ed19236e1c14b1ef2fbfd56af5e (patch)
tree4cd078c70911d25a53bd02b5c241bd0af89dda0b /example
parentbc7693c8b678a915fa7859bf8f0c99cca61ee021 (diff)
example: ipsec_api: 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_api/odp_ipsec.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/example/ipsec_api/odp_ipsec.c b/example/ipsec_api/odp_ipsec.c
index c7ae1be4e..3487b27b3 100644
--- a/example/ipsec_api/odp_ipsec.c
+++ b/example/ipsec_api/odp_ipsec.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <getopt.h>
+#include <signal.h>
#include <unistd.h>
#include <inttypes.h>
@@ -94,7 +95,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 */
@@ -147,6 +149,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);
+}
+
/**
* Allocate per packet processing context and associate it with
* packet buffer
@@ -734,7 +743,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_CONTINUE;
pkt_ctx_t *ctx;
odp_queue_t dispatchq;
@@ -917,6 +926,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;
@@ -949,6 +962,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);
@@ -1036,10 +1050,8 @@ 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;
@@ -1048,11 +1060,8 @@ main(int argc, char *argv[])
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 */