From 713b80f440cb414cd0b856bde0ea1b31f939777f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 9 Nov 2024 23:45:21 -0800 Subject: refactor initialization/finalization Applications must now call nng_init(), but they can supply a set of parameters optionally. The code is now safe for multiple libraries to do this concurrently, meaning nng_fini no longer can race against another instance starting up. The nni_init checks on all public APIs are removed now. --- src/tools/nngcat/nngcat.c | 3 +++ src/tools/perf/perf.c | 3 +++ src/tools/perf/pubdrop.c | 3 +++ 3 files changed, 9 insertions(+) (limited to 'src/tools') diff --git a/src/tools/nngcat/nngcat.c b/src/tools/nngcat/nngcat.c index 87f7c0a6..57bee3e5 100644 --- a/src/tools/nngcat/nngcat.c +++ b/src/tools/nngcat/nngcat.c @@ -723,6 +723,9 @@ main(int ac, char **av) addrend = &addrs; topicend = &topics; + nng_init(NULL); + atexit(nng_fini); + while ((rv = nng_opts_parse(ac, av, opts, &val, &arg, &idx)) == 0) { switch (val) { case OPT_HELP: diff --git a/src/tools/perf/perf.c b/src/tools/perf/perf.c index 2801ce51..c7057c73 100644 --- a/src/tools/perf/perf.c +++ b/src/tools/perf/perf.c @@ -189,6 +189,9 @@ main(int argc, char **argv) open_client = nng_pair0_open; #endif + nng_init(NULL); + atexit(nng_fini); + // Allow -m or whatever to override argv[0]. if ((argc >= 3) && (strcmp(argv[1], "-m") == 0)) { prog = argv[2]; diff --git a/src/tools/perf/pubdrop.c b/src/tools/perf/pubdrop.c index af715a88..020bae0f 100644 --- a/src/tools/perf/pubdrop.c +++ b/src/tools/perf/pubdrop.c @@ -75,6 +75,9 @@ main(int argc, char **argv) argc--; argv++; + nng_init(NULL); + atexit(nng_fini); + // We calculate a delay factor to roughly delay 1 usec. We don't // need this to be perfect, just reproducible on the same host. unsigned long cnt = 1000000; -- cgit v1.2.3-70-g09d2