From 70348e2d4725c9ec43f51811d290c22c782058ac Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 12 Jan 2017 18:34:58 -0800 Subject: Pull out the posix clock stuff for plat_clock. --- src/CMakeLists.txt | 3 +++ src/core/clock.c | 23 +++++++++++++++++++++++ src/core/clock.h | 19 +++++++++++++++++++ src/core/nng_impl.h | 4 +++- src/core/platform.h | 12 ++++++------ src/platform/posix/posix_clock.c | 8 ++++---- 6 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 src/core/clock.c create mode 100644 src/core/clock.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4380ff04..c26581ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,9 @@ set (NNG_SOURCES nng.h core/defs.h + + core/clock.c + core/clock.h core/endpt.c core/idhash.c core/idhash.h diff --git a/src/core/clock.c b/src/core/clock.c new file mode 100644 index 00000000..3e36358a --- /dev/null +++ b/src/core/clock.c @@ -0,0 +1,23 @@ +// +// 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_usleep(nni_duration usec) +{ + nni_plat_usleep(usec); +} diff --git a/src/core/clock.h b/src/core/clock.h new file mode 100644 index 00000000..c46adfbe --- /dev/null +++ b/src/core/clock.h @@ -0,0 +1,19 @@ +// +// 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. +// + +#ifndef CORE_CLOCK_H +#define CORE_CLOCK_H + +#include "core/nng_impl.h" + +extern nni_time nni_clock(void); + +extern void nni_usleep(nni_duration usec); + +#endif // CORE_CLOCK_H \ No newline at end of file diff --git a/src/core/nng_impl.h b/src/core/nng_impl.h index 6bf0900d..ff25f5ad 100644 --- a/src/core/nng_impl.h +++ b/src/core/nng_impl.h @@ -22,9 +22,11 @@ // those starting with nng_ are intended for external consumption. The latter // symbols should be found in the toplevel nng.h header. #include "core/defs.h" -#include "core/list.h" + +#include "core/clock.h" #include "core/idhash.h" #include "core/init.h" +#include "core/list.h" #include "core/message.h" #include "core/msgqueue.h" #include "core/options.h" diff --git a/src/core/platform.h b/src/core/platform.h index 2955215b..f7bec4ca 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -123,16 +123,16 @@ extern int nni_plat_thr_init(nni_plat_thr *, void (*)(void *), void *); // is an error to reference the thread in any further way. extern void nni_plat_thr_fini(nni_plat_thr *); -// nn_clock returns a number of microseconds since some arbitrary time +// nn_plat_clock returns a number of microseconds since some arbitrary time // in the past. The values returned by nni_clock must use the same base -// as the times used in nni_cond_waituntil. The nni_clock() must return -// values > 0, and must return values smaller than 2^63. (We could relax +// as the times used in nni_plat_cond_waituntil. The nni_plat_clock() must +// returnvalues > 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_clock(void); +extern nni_time nni_plat_clock(void); -// nni_usleep sleeps for the specified number of microseconds (at least). -extern void nni_usleep(nni_duration); +// nni_plat_usleep sleeps for the specified number of microseconds (at least). +extern void nni_plat_usleep(nni_duration); // nni_plat_init is called to allow the platform the chance to // do any necessary initialization. This routine MUST be idempotent, diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c index 215f66e6..6b452cbf 100644 --- a/src/platform/posix/posix_clock.c +++ b/src/platform/posix/posix_clock.c @@ -20,7 +20,7 @@ // Use POSIX realtime stuff nni_time -nni_clock(void) +nni_plat_clock(void) { struct timespec ts; nni_time usec; @@ -38,7 +38,7 @@ nni_clock(void) void -nni_usleep(nni_duration usec) +nni_plat_usleep(nni_duration usec) { struct timespec ts; @@ -70,7 +70,7 @@ nni_usleep(nni_duration usec) #include nni_time -nni_clock(void) +nni_plat_clock(void) { nni_time usec; @@ -88,7 +88,7 @@ nni_clock(void) void -nni_usleep(nni_duration usec) +nni_plat_usleep(nni_duration usec) { // So probably there is no nanosleep. We could in theory use // pthread condition variables, but that means doing memory -- cgit v1.2.3-70-g09d2