Move time utils to their own time.c file
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 13 Dec 2018 22:06:29 +0000 (17:06 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 14 Jan 2019 22:56:23 +0000 (17:56 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/Makefile.am
src/common/time.c [new file with mode: 0644]
src/common/utils.c
tests/unit/Makefile.am

index 1824fe46dcb601e561df0fea08b9e1c403ded65c..16e9e548b2a97ca747a3ce4170425f315db0bbf2 100644 (file)
@@ -27,7 +27,7 @@ libcommon_la_SOURCES = error.h error.c utils.c utils.h runas.h runas.c \
                        buffer-view.h buffer-view.c \
                        location.c \
                        waiter.h waiter.c \
-                       userspace-probe.c event.c
+                       userspace-probe.c event.c time.c
 
 if HAVE_ELF_H
 libcommon_la_SOURCES += lttng-elf.h lttng-elf.c
diff --git a/src/common/time.c b/src/common/time.c
new file mode 100644 (file)
index 0000000..5c55945
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <common/time.h>
+#include <common/macros.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <limits.h>
+#include <errno.h>
+#include <pthread.h>
+
+LTTNG_HIDDEN
+int timespec_to_ms(struct timespec ts, unsigned long *ms)
+{
+       unsigned long res, remain_ms;
+
+       if (ts.tv_sec > ULONG_MAX / MSEC_PER_SEC) {
+               errno = EOVERFLOW;
+               return -1;      /* multiplication overflow */
+       }
+       res = ts.tv_sec * MSEC_PER_SEC;
+       remain_ms = ULONG_MAX - res;
+       if (ts.tv_nsec / NSEC_PER_MSEC > remain_ms) {
+               errno = EOVERFLOW;
+               return -1;      /* addition overflow */
+       }
+       res += ts.tv_nsec / NSEC_PER_MSEC;
+       *ms = res;
+       return 0;
+}
+
+LTTNG_HIDDEN
+struct timespec timespec_abs_diff(struct timespec t1, struct timespec t2)
+{
+       uint64_t ts1 = (uint64_t) t1.tv_sec * (uint64_t) NSEC_PER_SEC +
+                       (uint64_t) t1.tv_nsec;
+       uint64_t ts2 = (uint64_t) t2.tv_sec * (uint64_t) NSEC_PER_SEC +
+                       (uint64_t) t2.tv_nsec;
+       uint64_t diff = max(ts1, ts2) - min(ts1, ts2);
+       struct timespec res;
+
+       res.tv_sec = diff / (uint64_t) NSEC_PER_SEC;
+       res.tv_nsec = diff % (uint64_t) NSEC_PER_SEC;
+       return res;
+}
index 08139e5e2cb23d691c92c6800cef841e2362bc57..3dc2d9297d4379ee99a6e127b17a84748dbf15de 100644 (file)
@@ -1646,38 +1646,3 @@ int utils_show_help(int section, const char *page_name,
 end:
        return ret;
 }
-
-LTTNG_HIDDEN
-int timespec_to_ms(struct timespec ts, unsigned long *ms)
-{
-       unsigned long res, remain_ms;
-
-       if (ts.tv_sec > ULONG_MAX / MSEC_PER_SEC) {
-               errno = EOVERFLOW;
-               return -1;      /* multiplication overflow */
-       }
-       res = ts.tv_sec * MSEC_PER_SEC;
-       remain_ms = ULONG_MAX - res;
-       if (ts.tv_nsec / NSEC_PER_MSEC > remain_ms) {
-               errno = EOVERFLOW;
-               return -1;      /* addition overflow */
-       }
-       res += ts.tv_nsec / NSEC_PER_MSEC;
-       *ms = res;
-       return 0;
-}
-
-LTTNG_HIDDEN
-struct timespec timespec_abs_diff(struct timespec t1, struct timespec t2)
-{
-       uint64_t ts1 = (uint64_t) t1.tv_sec * (uint64_t) NSEC_PER_SEC +
-                       (uint64_t) t1.tv_nsec;
-       uint64_t ts2 = (uint64_t) t2.tv_sec * (uint64_t) NSEC_PER_SEC +
-                       (uint64_t) t2.tv_nsec;
-       uint64_t diff = max(ts1, ts2) - min(ts1, ts2);
-       struct timespec res;
-
-       res.tv_sec = diff / (uint64_t) NSEC_PER_SEC;
-       res.tv_nsec = diff % (uint64_t) NSEC_PER_SEC;
-       return res;
-}
index b2804f697ac14507e60e163a1881643296b5f387..024ecc02650d624b21d6191edc561fef9be50058 100644 (file)
@@ -126,10 +126,8 @@ endif
 KERN_DATA_TRACE=$(top_builddir)/src/bin/lttng-sessiond/trace-kernel.$(OBJEXT) \
                $(top_builddir)/src/bin/lttng-sessiond/consumer.$(OBJEXT) \
                $(top_builddir)/src/bin/lttng-sessiond/utils.$(OBJEXT) \
-               $(top_builddir)/src/common/libcommon.la \
                $(top_builddir)/src/common/health/libhealth.la \
                $(top_builddir)/src/bin/lttng-sessiond/notification-thread-commands.$(OBJEXT) \
-               $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \
                $(LIBLTTNG_CTL)
 
 test_kernel_data_SOURCES = test_kernel_data.c
This page took 0.028013 seconds and 4 git commands to generate.