From fd871e6ce9de54f81f00918d4c7e3f3f4336b6d3 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 20 Feb 2018 19:41:55 -0800 Subject: Introduce 'porting layer' Public API. This introduces portable primitives for time, random numbers, synchronization primitives, and threading. These are somewhat primitive (least common denominiators), but they can help with writing portable applications, especially our own demo apps. --- perf/perf.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'perf') diff --git a/perf/perf.c b/perf/perf.c index 84a1c66f..593f635e 100644 --- a/perf/perf.c +++ b/perf/perf.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -16,11 +16,7 @@ #include #include -// We steal access to the clock and thread functions so that we can -// work on Windows too. These functions are *not* part of nng's public -// API, so don't be lazy like this! All nni_ symbols are subject to -// change without notice, and not part of the stable API or ABI. -#include "core/nng_impl.h" +#include "supplemental/util/platform.h" #if defined(NNG_ENABLE_PAIR1) #include "protocol/pair1/pair.h" @@ -224,11 +220,10 @@ do_inproc(void *args) void do_inproc_lat(int argc, char **argv) { - nni_thr thr; + nng_thread *thr; struct inproc_args ia; int rv; - nni_init(); if (argc != 2) { die("Usage: inproc_lat "); } @@ -238,26 +233,24 @@ do_inproc_lat(int argc, char **argv) ia.count = parse_int(argv[1], "count"); ia.func = latency_server; - if ((rv = nni_thr_init(&thr, do_inproc, &ia)) != 0) { + if ((rv = nng_thread_create(&thr, do_inproc, &ia)) != 0) { die("Cannot create thread: %s", nng_strerror(rv)); } - nni_thr_run(&thr); // Sleep a bit. nng_msleep(100); latency_client("inproc://latency_test", ia.msgsize, ia.count); - nni_thr_fini(&thr); + nng_thread_destroy(thr); } void do_inproc_thr(int argc, char **argv) { - nni_thr thr; + nng_thread *thr; struct inproc_args ia; int rv; - nni_init(); if (argc != 2) { die("Usage: inproc_thr "); } @@ -267,12 +260,11 @@ do_inproc_thr(int argc, char **argv) ia.count = parse_int(argv[1], "count"); ia.func = throughput_client; - if ((rv = nni_thr_init(&thr, do_inproc, &ia)) != 0) { + if ((rv = nng_thread_create(&thr, do_inproc, &ia)) != 0) { die("Cannot create thread: %s", nng_strerror(rv)); } - nni_thr_run(&thr); throughput_server("inproc://tput_test", ia.msgsize, ia.count); - nni_thr_fini(&thr); + nng_thread_destroy(thr); } void @@ -280,7 +272,7 @@ latency_client(const char *addr, size_t msgsize, int trips) { nng_socket s; nng_msg * msg; - nni_time start, end; + nng_time start, end; int rv; int i; float total; @@ -301,7 +293,7 @@ latency_client(const char *addr, size_t msgsize, int trips) die("nng_msg_alloc: %s", nng_strerror(rv)); } - start = nni_clock(); + start = nng_clock(); for (i = 0; i < trips; i++) { if ((rv = nng_sendmsg(s, msg, 0)) != 0) { die("nng_sendmsg: %s", nng_strerror(rv)); @@ -311,9 +303,9 @@ latency_client(const char *addr, size_t msgsize, int trips) die("nng_recvmsg: %s", nng_strerror(rv)); } } - end = nni_clock(); + end = nng_clock(); - nni_msg_free(msg); + nng_msg_free(msg); nng_close(s); total = (float) ((end - start)) / 1000; @@ -395,8 +387,8 @@ throughput_server(const char *addr, size_t msgsize, int count) if ((rv = nng_recvmsg(s, &msg, 0)) != 0) { die("nng_recvmsg: %s", nng_strerror(rv)); } - nni_msg_free(msg); - start = nni_clock(); + nng_msg_free(msg); + start = nng_clock(); for (i = 0; i < count; i++) { if ((rv = nng_recvmsg(s, &msg, 0)) != 0) { @@ -406,9 +398,9 @@ throughput_server(const char *addr, size_t msgsize, int count) die("wrong message size: %d != %d", nng_msg_len(msg), msgsize); } - nni_msg_free(msg); + nng_msg_free(msg); } - end = nni_clock(); + end = nng_clock(); nng_close(s); total = (float) ((end - start)) / 1000; msgpersec = (float) (count) / total; -- cgit v1.2.3-70-g09d2