Mercurial > njs
changeset 677:2ad7533bcbae
Added nxt_time().
Returns the current high-resolution real time.
| author | Artem S. Povalyukhin <artem.povaluhin@gmail.com> |
|---|---|
| date | Wed, 28 Nov 2018 21:50:28 +0300 |
| parents | cf424d6313ae |
| children | b7706e03babc |
| files | Makefile nxt/Makefile nxt/auto/time nxt/nxt_time.c nxt/nxt_time.h |
| diffstat | 5 files changed, 92 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Thu Nov 29 18:14:12 2018 +0300 +++ b/Makefile Wed Nov 28 21:50:28 2018 +0300 @@ -48,6 +48,7 @@ $(NXT_BUILDDIR)/nxt_sha1.o \ $(NXT_BUILDDIR)/nxt_sha2.o \ $(NXT_BUILDDIR)/nxt_pcre.o \ + $(NXT_BUILDDIR)/nxt_time.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ @@ -93,6 +94,7 @@ $(NXT_BUILDDIR)/nxt_sha1.o \ $(NXT_BUILDDIR)/nxt_sha2.o \ $(NXT_BUILDDIR)/nxt_pcre.o \ + $(NXT_BUILDDIR)/nxt_time.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ @@ -535,7 +537,7 @@ -I$(NXT_LIB) $(NXT_EDITLINE_CFLAGS) -Injs \ njs/njs_shell.c \ $(NXT_BUILDDIR)/libnjs.a \ - -lm $(NXT_PCRE_LIB) $(NXT_EDITLINE_LIB) + -lm $(NXT_PCRE_LIB) $(NXT_LIBRT) $(NXT_EDITLINE_LIB) $(NXT_BUILDDIR)/njs_unit_test: \ $(NXT_BUILDDIR)/libnxt.a \ @@ -546,7 +548,7 @@ -I$(NXT_LIB) -Injs \ njs/test/njs_unit_test.c \ $(NXT_BUILDDIR)/libnjs.a \ - -lm $(NXT_PCRE_LIB) + -lm $(NXT_PCRE_LIB) $(NXT_LIBRT) $(NXT_BUILDDIR)/njs_interactive_test: \ $(NXT_BUILDDIR)/libnxt.a \ @@ -557,7 +559,7 @@ -I$(NXT_LIB) -Injs \ njs/test/njs_interactive_test.c \ $(NXT_BUILDDIR)/libnjs.a \ - -lm $(NXT_PCRE_LIB) + -lm $(NXT_PCRE_LIB) $(NXT_LIBRT) $(NXT_BUILDDIR)/njs_benchmark: \ $(NXT_BUILDDIR)/libnxt.a \ @@ -568,6 +570,6 @@ -I$(NXT_LIB) -Injs \ njs/test/njs_benchmark.c \ $(NXT_BUILDDIR)/libnjs.a \ - -lm $(NXT_PCRE_LIB) + -lm $(NXT_PCRE_LIB) $(NXT_LIBRT) include $(NXT_LIB)/Makefile
--- a/nxt/Makefile Thu Nov 29 18:14:12 2018 +0300 +++ b/nxt/Makefile Wed Nov 28 21:50:28 2018 +0300 @@ -20,6 +20,7 @@ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_trace.o \ + $(NXT_BUILDDIR)/nxt_time.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ ar -r -c $(NXT_BUILDDIR)/libnxt.a \ @@ -37,6 +38,7 @@ $(NXT_BUILDDIR)/nxt_sha2.o \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ + $(NXT_BUILDDIR)/nxt_time.o \ $(NXT_BUILDDIR)/nxt_trace.o \ $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ @@ -206,6 +208,17 @@ -I$(NXT_LIB) \ $(NXT_LIB)/nxt_malloc.c +$(NXT_BUILDDIR)/nxt_time.o: \ + $(NXT_LIB)/nxt_auto_config.h \ + $(NXT_LIB)/nxt_types.h \ + $(NXT_LIB)/nxt_clang.h \ + $(NXT_LIB)/nxt_time.h \ + $(NXT_LIB)/nxt_time.c \ + + $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_time.o $(NXT_CFLAGS) \ + -I$(NXT_LIB) \ + $(NXT_LIB)/nxt_time.c + $(NXT_BUILDDIR)/nxt_trace.o: \ $(NXT_LIB)/nxt_auto_config.h \ $(NXT_LIB)/nxt_types.h \
--- a/nxt/auto/time Thu Nov 29 18:14:12 2018 +0300 +++ b/nxt/auto/time Wed Nov 28 21:50:28 2018 +0300 @@ -3,6 +3,46 @@ # Copyright (C) NGINX, Inc. +nxt_feature="clock_gettime(CLOCK_MONOTONIC)" +nxt_feature_name=NXT_HAVE_CLOCK_MONOTONIC +nxt_feature_run=yes +nxt_feature_incs= +nxt_feature_libs= +nxt_feature_test="#include <time.h> + + int main() { + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) + return 1; + return 0; + }" +. ${NXT_AUTO}feature + + +if [ $nxt_found = no ]; then + + # Linux and Solaris 10 clock_gettime() are in librt. + + nxt_feature="clock_gettime(CLOCK_MONOTONIC) in librt" + nxt_feature_libs="-lrt" + . ${NXT_AUTO}feature +fi + +if [ $nxt_found = yes ]; then + cat << END >> $NXT_MAKEFILE_CONF + +NXT_LIBRT = -lrt +END + +else + cat << END >> $NXT_MAKEFILE_CONF + +NXT_LIBRT = +END + +fi + # Linux, FreeBSD, MacOSX. nxt_feature="struct tm.tm_gmtoff"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nxt/nxt_time.c Wed Nov 28 21:50:28 2018 +0300 @@ -0,0 +1,30 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#include <nxt_auto_config.h> +#include <nxt_types.h> +#include <nxt_clang.h> +#include <nxt_time.h> + +#include <time.h> + +uint64_t +nxt_time(void) +{ +#if (NXT_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 +}
