From d3c3e699c7a76ae45507ba6a8f12fb5147ac6d6d Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 14 Feb 2024 21:33:56 -0800 Subject: [PATCH] Moved njs_time() out of the core as it is not a part of the spec. --- 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(-) delete mode 100644 src/njs_time.c delete mode 100644 src/njs_time.h diff --git a/auto/sources b/auto/sources index d675b739..d97021c9 100644 --- a/auto/sources +++ b/auto/sources @@ -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 --git a/external/njs_shell.c b/external/njs_shell.c index 9af73b73..65c4c264 100644 --- a/external/njs_shell.c +++ b/external/njs_shell.c @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -169,6 +168,7 @@ static void njs_console_logger(njs_log_level_t level, const u_char *start, 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_t *node1, njs_rbtree_node_t *node2) 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 --git a/src/njs_date.c b/src/njs_date.c index 8f0850ab..49ac3fc0 100644 --- a/src/njs_date.c +++ b/src/njs_date.c @@ -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 --git a/src/njs_main.h b/src/njs_main.h index afb024e1..f52ee9a4 100644 --- a/src/njs_main.h +++ b/src/njs_main.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/njs_time.c b/src/njs_time.c deleted file mode 100644 index 68733c73..00000000 --- a/src/njs_time.c +++ /dev/null @@ -1,27 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - * Copyright (C) NGINX, Inc. - */ - - -#include - - -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 --git a/src/njs_time.h b/src/njs_time.h deleted file mode 100644 index d3751206..00000000 --- a/src/njs_time.h +++ /dev/null @@ -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 --git a/src/test/njs_benchmark.c b/src/test/njs_benchmark.c index 8ae38e45..a99e7506 100644 --- a/src/test/njs_benchmark.c +++ b/src/test/njs_benchmark.c @@ -35,6 +35,25 @@ njs_module_t *njs_benchmark_addon_external_modules[] = { }; +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) -- 2.47.3