aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/posix/posix_clock.c')
-rw-r--r--src/platform/posix/posix_clock.c44
1 files changed, 17 insertions, 27 deletions
diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c
index c772263c..4307fa89 100644
--- a/src/platform/posix/posix_clock.c
+++ b/src/platform/posix/posix_clock.c
@@ -1,23 +1,10 @@
/*
* Copyright 2016 Garrett D'Amore <garrett@damore.org>
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
+ * 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.
*/
/*
@@ -38,17 +25,16 @@
#include <errno.h>
#include <string.h>
-#ifndef NNG_USE_GETTIMEOFDAY
+#ifndef NNG_USE_GETTIMEOFDAY
/*
* Use POSIX realtime stuff.
*/
-
uint64_t
nni_clock(void)
{
- struct timespec ts;
- uint64_t usec;
+ struct timespec ts;
+ uint64_t usec;
if (clock_gettime(NNG_USE_CLOCKID, &ts) != 0) {
/* This should never ever occur. */
@@ -76,7 +62,8 @@ nni_usleep(uint64_t usec)
}
}
-#else /* NNG_USE_GETTIMEOFDAY */
+
+#else /* NNG_USE_GETTIMEOFDAY */
/*
* If you're here, its because you don't have a modern clock_gettime with
@@ -98,6 +85,7 @@ nni_clock(void)
uint64_t usec;
struct timeval tv;
+
if (gettimeofday(&tv, NULL) != 0) {
nni_panic("gettimeofday failed: %s", strerror(errno));
}
@@ -108,6 +96,7 @@ nni_clock(void)
return (usec);
}
+
void
nni_usleep(uint64_t usec)
{
@@ -133,7 +122,7 @@ nni_usleep(uint64_t usec)
pfd.fd = -1;
pfd.events = 0;
- now = nni_clock();
+ now = nni_clock();
expire = now + usec;
while (now < expire) {
@@ -144,11 +133,12 @@ nni_usleep(uint64_t usec)
* early. So this gives us a better chance to avoid adding
* nearly an extra unneeded millisecond to the wait.
*/
- (void) poll(&pfd, 0, (int)((expire - now) / 1000));
- now = nni_clock();
+ (void) poll(&pfd, 0, (int) ((expire - now) / 1000));
+ now = nni_clock();
}
}
-#endif /* NNG_USE_GETTIMEOFDAY */
-#endif /* PLATFORM_POSIX_CLOCK */
+#endif /* NNG_USE_GETTIMEOFDAY */
+
+#endif /* PLATFORM_POSIX_CLOCK */