aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-12 18:34:58 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-12 21:34:23 -0800
commit70348e2d4725c9ec43f51811d290c22c782058ac (patch)
treed85ff38b4cb7d1ae0bbbc6b93f010fe5670181b0
parentda88419ae8165248621cad26df72a0d91663d50b (diff)
downloadnng-70348e2d4725c9ec43f51811d290c22c782058ac.tar.gz
nng-70348e2d4725c9ec43f51811d290c22c782058ac.tar.bz2
nng-70348e2d4725c9ec43f51811d290c22c782058ac.zip
Pull out the posix clock stuff for plat_clock.
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/core/clock.c23
-rw-r--r--src/core/clock.h19
-rw-r--r--src/core/nng_impl.h4
-rw-r--r--src/core/platform.h12
-rw-r--r--src/platform/posix/posix_clock.c8
7 files changed, 59 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 466ac92e..aca10b92 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,6 +104,7 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
add_definitions (-DPLATFORM_WINDOWS)
set (NNG_HAVE_WINSOCK 1)
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
+ add_definitions (-D_CRT_RAND_S)
# Target Windows Vista and later
add_definitions (-D_WIN32_WINNT=0x0600)
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 <garrett@damore.org>
+//
+// 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 <garrett@damore.org>
+//
+// 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 <poll.h>
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