[njs] Moved njs_time() out of the core as it is not a part of the spec.

Dmitry Volyntsev xeioex at nginx.com
Thu Feb 15 05:35:03 UTC 2024


details:   https://hg.nginx.org/njs/rev/6fa96ea99037
branches:  
changeset: 2287:6fa96ea99037
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Feb 14 21:33:56 2024 -0800
description:
Moved njs_time() out of the core as it is not a part of the spec.

diffstat:

 auto/sources             |   1 -
 external/njs_shell.c     |  21 ++++++++++++++++++++-
 src/njs_date.c           |  13 +++++++++++++
 src/njs_main.h           |   1 -
 src/njs_time.c           |  27 ---------------------------
 src/njs_time.h           |  27 ---------------------------
 src/test/njs_benchmark.c |  19 +++++++++++++++++++
 7 files changed, 52 insertions(+), 57 deletions(-)

diffs (178 lines):

diff -r d3a9f2f153f8 -r 6fa96ea99037 auto/sources
--- a/auto/sources	Wed Feb 07 17:57:02 2024 -0800
+++ b/auto/sources	Wed Feb 14 21:33:56 2024 -0800
@@ -16,7 +16,6 @@ NJS_LIB_SRCS=" \
    src/njs_md5.c \
    src/njs_sha1.c \
    src/njs_sha2.c \
-   src/njs_time.c \
    src/njs_malloc.c \
    src/njs_mp.c \
    src/njs_sprintf.c \
diff -r d3a9f2f153f8 -r 6fa96ea99037 external/njs_shell.c
--- a/external/njs_shell.c	Wed Feb 07 17:57:02 2024 -0800
+++ b/external/njs_shell.c	Wed Feb 14 21:33:56 2024 -0800
@@ -7,7 +7,6 @@
 
 #include <njs.h>
 #include <njs_unix.h>
-#include <njs_time.h>
 #include <njs_arr.h>
 #include <njs_queue.h>
 #include <njs_rbtree.h>
@@ -169,6 +168,7 @@ static void njs_console_logger(njs_log_l
 
 static intptr_t njs_event_rbtree_compare(njs_rbtree_node_t *node1,
     njs_rbtree_node_t *node2);
+static uint64_t njs_time(void);
 
 njs_int_t njs_array_buffer_detach(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused, njs_value_t *retval);
@@ -2122,3 +2122,22 @@ njs_event_rbtree_compare(njs_rbtree_node
 
     return 0;
 }
+
+
+static uint64_t
+njs_time(void)
+{
+#if (NJS_HAVE_CLOCK_MONOTONIC)
+    struct timespec ts;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts);
+
+    return (uint64_t) ts.tv_sec * 1000000000 + ts.tv_nsec;
+#else
+    struct timeval tv;
+
+    gettimeofday(&tv, NULL);
+
+    return (uint64_t) tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+#endif
+}
diff -r d3a9f2f153f8 -r 6fa96ea99037 src/njs_date.c
--- a/src/njs_date.c	Wed Feb 07 17:57:02 2024 -0800
+++ b/src/njs_date.c	Wed Feb 14 21:33:56 2024 -0800
@@ -22,6 +22,19 @@
 #define NJS_DATE_MSEC                   7
 
 
+#if (NJS_HAVE_TM_GMTOFF)
+
+#define njs_timezone(tm)                                                      \
+    ((tm)->tm_gmtoff)
+
+#elif (NJS_HAVE_ALTZONE)
+
+#define njs_timezone(tm)                                                      \
+    (-(((tm)->tm_isdst > 0) ? altzone : timezone))
+
+#endif
+
+
 #define njs_date_magic(field, local)                                          \
     ((local << 6) + field)
 
diff -r d3a9f2f153f8 -r 6fa96ea99037 src/njs_main.h
--- a/src/njs_main.h	Wed Feb 07 17:57:02 2024 -0800
+++ b/src/njs_main.h	Wed Feb 14 21:33:56 2024 -0800
@@ -27,7 +27,6 @@
 #include <njs_queue.h>
 #include <njs_flathsh.h>
 #include <njs_random.h>
-#include <njs_time.h>
 #include <njs_malloc.h>
 #include <njs_rbtree.h>
 #include <njs_mp.h>
diff -r d3a9f2f153f8 -r 6fa96ea99037 src/njs_time.c
--- a/src/njs_time.c	Wed Feb 07 17:57:02 2024 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) NGINX, Inc.
- */
-
-
-#include <njs_main.h>
-
-
-uint64_t
-njs_time(void)
-{
-#if (NJS_HAVE_CLOCK_MONOTONIC)
-    struct timespec ts;
-
-    clock_gettime(CLOCK_MONOTONIC, &ts);
-
-    return (uint64_t) ts.tv_sec * 1000000000 + ts.tv_nsec;
-#else
-    struct timeval tv;
-
-    gettimeofday(&tv, NULL);
-
-    return (uint64_t) tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
-#endif
-}
diff -r d3a9f2f153f8 -r 6fa96ea99037 src/njs_time.h
--- a/src/njs_time.h	Wed Feb 07 17:57:02 2024 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) NGINX, Inc.
- */
-
-#ifndef _NJS_TIME_H_INCLUDED_
-#define _NJS_TIME_H_INCLUDED_
-
-
-#if (NJS_HAVE_TM_GMTOFF)
-
-#define njs_timezone(tm)                                                      \
-    ((tm)->tm_gmtoff)
-
-#elif (NJS_HAVE_ALTZONE)
-
-#define njs_timezone(tm)                                                      \
-    (-(((tm)->tm_isdst > 0) ? altzone : timezone))
-
-#endif
-
-
-uint64_t njs_time(void);
-
-
-#endif /* _NJS_TIME_H_INCLUDED_ */
diff -r d3a9f2f153f8 -r 6fa96ea99037 src/test/njs_benchmark.c
--- a/src/test/njs_benchmark.c	Wed Feb 07 17:57:02 2024 -0800
+++ b/src/test/njs_benchmark.c	Wed Feb 14 21:33:56 2024 -0800
@@ -35,6 +35,25 @@ njs_module_t *njs_benchmark_addon_extern
 };
 
 
+static uint64_t
+njs_time(void)
+{
+#if (NJS_HAVE_CLOCK_MONOTONIC)
+    struct timespec ts;
+
+    clock_gettime(CLOCK_MONOTONIC, &ts);
+
+    return (uint64_t) ts.tv_sec * 1000000000 + ts.tv_nsec;
+#else
+    struct timeval tv;
+
+    gettimeofday(&tv, NULL);
+
+    return (uint64_t) tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+#endif
+}
+
+
 static njs_int_t
 njs_benchmark_test(njs_vm_t *parent, njs_opts_t *opts, njs_value_t *report,
     njs_benchmark_test_t *test)


More information about the nginx-devel mailing list