summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-01-14 21:42:04 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-01-14 21:42:04 +0300
commit593550b8eea8998c3b6b9e9eb3e04eec82854ae2 (patch)
tree72f2f27fa4f69bbe03e00d7d07f7cbe588876f3b /plugins/Dbx_mdbx/src/libmdbx/test/chrono.h
parent742ec0af9b72863a6af8da9ff88128b1f3da090b (diff)
libmdbx added as set of files
Diffstat (limited to 'plugins/Dbx_mdbx/src/libmdbx/test/chrono.h')
-rw-r--r--plugins/Dbx_mdbx/src/libmdbx/test/chrono.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h b/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h
new file mode 100644
index 0000000000..d5e9f658d1
--- /dev/null
+++ b/plugins/Dbx_mdbx/src/libmdbx/test/chrono.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2017 Leonid Yuriev <leo@yuriev.ru>
+ * and other libmdbx authors: please see AUTHORS file.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+
+#pragma once
+
+#include "base.h"
+#include "log.h"
+#include "utils.h"
+
+namespace chrono {
+
+#pragma pack(push, 1)
+
+typedef union time {
+ uint64_t fixedpoint;
+ struct {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+ uint32_t fractional;
+ union {
+ uint32_t utc;
+ uint32_t integer;
+ };
+#else
+ union {
+ uint32_t utc;
+ uint32_t integer;
+ };
+ uint32_t fractional;
+#endif
+ };
+
+ void reset() { fixedpoint = 0; }
+ uint32_t seconds() const { return utc; }
+} time;
+
+#pragma pack(pop)
+
+uint32_t ns2fractional(uint32_t);
+uint32_t fractional2ns(uint32_t);
+uint32_t us2fractional(uint32_t);
+uint32_t fractional2us(uint32_t);
+uint32_t ms2fractional(uint32_t);
+uint32_t fractional2ms(uint32_t);
+
+time from_ns(uint64_t us);
+time from_us(uint64_t ns);
+time from_ms(uint64_t ms);
+
+inline time from_seconds(uint64_t seconds) {
+ assert(seconds < UINT32_MAX);
+ time result;
+ result.fixedpoint = seconds << 32;
+ return result;
+}
+
+inline time from_utc(time_t utc) {
+ assert(utc >= 0);
+ return from_seconds((uint64_t)utc);
+}
+
+inline time infinite() {
+ time result;
+ result.fixedpoint = UINT64_MAX;
+ return result;
+}
+
+#if defined(HAVE_TIMESPEC_TV_NSEC) || defined(__timespec_defined) || \
+ defined(CLOCK_REALTIME)
+inline time from_timespec(const struct timespec &ts) {
+ time result;
+ result.fixedpoint =
+ ((uint64_t)ts.tv_sec << 32) | ns2fractional((uint32_t)ts.tv_nsec);
+ return result;
+}
+#endif /* HAVE_TIMESPEC_TV_NSEC */
+
+#if defined(HAVE_TIMEVAL_TV_USEC) || defined(_STRUCT_TIMEVAL)
+inline time from_timeval(const struct timeval &tv) {
+ time result;
+ result.fixedpoint =
+ ((uint64_t)tv.tv_sec << 32) | us2fractional((uint32_t)tv.tv_usec);
+ return result;
+}
+#endif /* HAVE_TIMEVAL_TV_USEC */
+
+time now_realtime();
+time now_motonic();
+
+} /* namespace chrono */