From 9f0fcbd84a6ee3655f55629ed4b01d13647ac0c9 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 22 Jul 2021 00:57:13 -0700 Subject: Remove extra wrapper for platform clock support. --- src/core/CMakeLists.txt | 2 -- src/core/clock.c | 22 ---------------------- src/core/clock.h | 20 -------------------- src/core/nng_impl.h | 3 +-- src/core/platform.h | 10 +++++----- src/platform/posix/posix_clock.c | 14 +++++++------- src/platform/windows/win_clock.c | 4 ++-- src/platform/windows/win_thread.c | 4 ++-- src/supplemental/util/platform.c | 4 ++-- 9 files changed, 19 insertions(+), 64 deletions(-) delete mode 100644 src/core/clock.c delete mode 100644 src/core/clock.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 040df7f4..b55bd70a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -20,8 +20,6 @@ nng_sources( aio.c aio.h - clock.c - clock.h device.c device.h dialer.c diff --git a/src/core/clock.c b/src/core/clock.c deleted file mode 100644 index 49b972e7..00000000 --- a/src/core/clock.c +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright 2017 Garrett D'Amore -// -// This software is supplied under the terms of the MIT License, a -// copy of which should be located in the distribution where this -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#include "core/nng_impl.h" - -nni_time -nni_clock(void) -{ - return (nni_plat_clock()); -} - -void -nni_msleep(nni_duration msec) -{ - nni_plat_sleep(msec); -} diff --git a/src/core/clock.h b/src/core/clock.h deleted file mode 100644 index b369520b..00000000 --- a/src/core/clock.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright 2017 Garrett D'Amore -// Copyright 2017 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 -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#ifndef CORE_CLOCK_H -#define CORE_CLOCK_H - -#include "core/nng_impl.h" - -extern nni_time nni_clock(void); - -extern void nni_msleep(nni_duration); - -#endif // CORE_CLOCK_H diff --git a/src/core/nng_impl.h b/src/core/nng_impl.h index a9e5560d..15db8d16 100644 --- a/src/core/nng_impl.h +++ b/src/core/nng_impl.h @@ -1,5 +1,5 @@ // -// Copyright 2017 Garrett D'Amore +// Copyright 2021 Garrett D'Amore // Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -27,7 +27,6 @@ #include "core/platform.h" #include "core/aio.h" -#include "core/clock.h" #include "core/device.h" #include "core/file.h" #include "core/idhash.h" diff --git a/src/core/platform.h b/src/core/platform.h index 5739811f..f1127c5b 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -236,16 +236,16 @@ extern bool nni_atomic_cas(nni_atomic_int *, int, int); // Clock Support // -// nn_plat_clock returns a number of milliseconds since some arbitrary time +// nn_clock returns a number of milliseconds since some arbitrary time // in the past. The values returned by nni_clock must use the same base -// as the times used in nni_plat_cond_until. The nni_plat_clock() must +// as the times used in nni_plat_cond_until. The nni_clock() must // return values > 0, and must return values smaller than 2^63. (We could // relax this last constraint, but there is no reason to, and leaves us the // option of using negative values for other purposes in the future.) -extern nni_time nni_plat_clock(void); +extern nni_time nni_clock(void); -// nni_plat_sleep sleeps for the specified number of milliseconds (at least). -extern void nni_plat_sleep(nni_duration); +// nni_msleep sleeps for the specified number of milliseconds (at least). +extern void nni_msleep(nni_duration); // // Entropy Support diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c index 1fa05cb1..d5435009 100644 --- a/src/platform/posix/posix_clock.c +++ b/src/platform/posix/posix_clock.c @@ -1,5 +1,5 @@ // -// Copyright 2017 Garrett D'Amore +// Copyright 2021 Garrett D'Amore // Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -21,7 +21,7 @@ // Use POSIX realtime stuff nni_time -nni_plat_clock(void) +nni_clock(void) { struct timespec ts; nni_time msec; @@ -38,7 +38,7 @@ nni_plat_clock(void) } void -nni_plat_sleep(nni_duration ms) +nni_msleep(nni_duration ms) { struct timespec ts; @@ -69,7 +69,7 @@ nni_plat_sleep(nni_duration ms) #include nni_time -nni_plat_clock(void) +nni_clock(void) { nni_time ms; @@ -86,7 +86,7 @@ nni_plat_clock(void) } void -nni_plat_sleep(nni_duration ms) +nni_msleep(nni_duration ms) { // So probably there is no nanosleep. We could in theory use // pthread condition variables, but that means doing memory @@ -105,12 +105,12 @@ nni_plat_sleep(nni_duration ms) pfd.fd = -1; pfd.events = 0; - now = nni_plat_clock(); // XXX: until nni_plat_clock returns ms. + now = nni_clock(); expire = now + ms; while (now < expire) { (void) poll(&pfd, 0, (int) (expire - now)); - now = nni_plat_clock(); + now = nni_clock(); } } diff --git a/src/platform/windows/win_clock.c b/src/platform/windows/win_clock.c index 613af4be..fc338fdb 100644 --- a/src/platform/windows/win_clock.c +++ b/src/platform/windows/win_clock.c @@ -13,14 +13,14 @@ #ifdef NNG_PLATFORM_WINDOWS nni_time -nni_plat_clock(void) +nni_clock(void) { // We are limited by the system clock, but that is ok. return (GetTickCount64()); } void -nni_plat_sleep(nni_duration dur) +nni_msleep(nni_duration dur) { uint64_t exp; diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index c069d3c9..dc9ed12a 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -144,7 +144,7 @@ nni_plat_cv_until(nni_plat_cv *cv, nni_time until) DWORD msec; BOOL ok; - now = nni_plat_clock(); + now = nni_clock(); if (now > until) { msec = 0; } else { diff --git a/src/supplemental/util/platform.c b/src/supplemental/util/platform.c index 8898b680..ddc2d088 100644 --- a/src/supplemental/util/platform.c +++ b/src/supplemental/util/platform.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -18,7 +18,7 @@ nng_time nng_clock(void) { (void) nni_init(); - return (nni_plat_clock()); + return (nni_clock()); } // Sleep for specified msecs. -- cgit v1.2.3-70-g09d2