diff options
-rw-r--r-- | CMakeLists.txt | 65 | ||||
-rw-r--r-- | source/kit/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/kit/mutex.h | 4 | ||||
-rw-r--r-- | source/kit/secure_random.c | 2 | ||||
-rw-r--r-- | source/kit/secure_random.h | 2 | ||||
-rw-r--r-- | source/kit/thread.h | 4 | ||||
-rw-r--r-- | source/kit/time.c | 65 | ||||
-rw-r--r-- | source/kit/time.h | 33 |
8 files changed, 11 insertions, 167 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f24fe6f..07b2738 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,53 +35,6 @@ include(CheckCSourceRuns) check_c_source_runs( " - #include <time.h> - int main() { - struct timespec t; - (void) t.tv_sec; - (void) t.tv_nsec; - return 0; - } - " - KIT_HAVE_STRUCT_TIMESPEC -) - -check_c_source_runs( - " - #include <bits/types/struct_timespec.h> - int main() { - return 0; - } - " - KIT_HAVE_BITS_TYPES_STRUCT_TIMESPEC_H -) - -check_c_source_runs( - " - #include <time.h> - int main() { - struct timespec t; - timespec_get(&t, TIME_UTC); - return 0; - } - " - KIT_HAVE_TIMESPEC_GET -) - -check_c_source_runs( - " - #include <time.h> - int main() { - struct timespec t; - clock_gettime(CLOCK_REALTIME, &t) - return 0; - } - " - KIT_HAVE_CLOCK_GETTIME -) - -check_c_source_runs( - " #include <pthread.h> int main() { pthread_mutexattr_t attr; @@ -105,7 +58,7 @@ check_c_source_runs( check_c_source_runs( " - #include <windows.h> + #include <Windows.h> int main() { return 0; } @@ -133,22 +86,6 @@ if(NOT KIT_HAVE_MALLOC) set(KIT_DISABLE_SYSTEM_MALLOC ON) endif() -if(NOT KIT_HAVE_STRUCT_TIMESPEC) - target_compile_definitions(kit PUBLIC KIT_NEED_STRUCT_TIMESPEC) -endif() - -if(KIT_HAVE_BITS_TYPES_STRUCT_TIMESPEC_H) - target_compile_definitions(kit PUBLIC KIT_HAVE_BITS_TYPES_STRUCT_TIMESPEC_H) -endif() - -if(NOT KIT_HAVE_TIMESPEC_GET) - target_compile_definitions(kit PUBLIC KIT_NEED_TIMESPEC_GET) -endif() - -if(KIT_HAVE_CLOCK_GETTIME) - target_compile_definitions(kit PUBLIC KIT_HAVE_CLOCK_GETTIME) -endif() - if(KIT_HAVE_PTHREAD_MUTEXATTR_SETTYPE) target_compile_definitions(kit PUBLIC KIT_HAVE_PTHREAD_MUTEXATTR_SETTYPE) endif() diff --git a/source/kit/CMakeLists.txt b/source/kit/CMakeLists.txt index b672a80..101e2a8 100644 --- a/source/kit/CMakeLists.txt +++ b/source/kit/CMakeLists.txt @@ -1,7 +1,7 @@ target_sources( kit PRIVATE - input_buffer.c bigint.c status.c time.c secure_random.c + input_buffer.c bigint.c status.c secure_random.c thread.posix.c atomic.win32.c condition_variable.c thread.win32.c move_back.c input_stream.c lower_bound.c file.c string_ref.c async_function.c allocator.c array_ref.c dynamic_array.c mutex.c @@ -9,7 +9,6 @@ target_sources( PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/mutex.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/status.h> - $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/time.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/atomic.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/allocator.h> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/string_ref.h> diff --git a/source/kit/mutex.h b/source/kit/mutex.h index 6d2d230..7816301 100644 --- a/source/kit/mutex.h +++ b/source/kit/mutex.h @@ -3,7 +3,9 @@ #ifndef KIT_DISABLE_SYSTEM_THREADS # include "thread_defs.h" -# include "time.h" + +# define _GNU_SOURCE +# include <time.h> # if !defined(_WIN32) || defined(__CYGWIN__) # include <pthread.h> diff --git a/source/kit/secure_random.c b/source/kit/secure_random.c index 3112167..5629daf 100644 --- a/source/kit/secure_random.c +++ b/source/kit/secure_random.c @@ -3,7 +3,7 @@ #include "condition_variable.h" #include "mersenne_twister_64.h" #include "mutex.h" -#include "time.h" + #include <assert.h> #include <stdio.h> diff --git a/source/kit/secure_random.h b/source/kit/secure_random.h index 758478d..e7a80c2 100644 --- a/source/kit/secure_random.h +++ b/source/kit/secure_random.h @@ -2,6 +2,8 @@ #define KIT_SECURE_RANDOM_H #include "status.h" + +#define _GNU_SOURCE #include <stddef.h> #include <stdint.h> diff --git a/source/kit/thread.h b/source/kit/thread.h index eff2684..e8fb7e8 100644 --- a/source/kit/thread.h +++ b/source/kit/thread.h @@ -3,8 +3,10 @@ #ifndef KIT_DISABLE_SYSTEM_THREADS # include "thread_defs.h" -# include "time.h" + +# define _GNU_SOURCE # include <stddef.h> +# include <time.h> # if defined(__cplusplus) # define _Noreturn [[noreturn]] diff --git a/source/kit/time.c b/source/kit/time.c deleted file mode 100644 index ccd3835..0000000 --- a/source/kit/time.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "time.h" - -#ifdef KIT_NEED_TIMESPEC_GET - -# if defined(_WIN32) && !defined(__CYGWIN__) - -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN 1 -# endif -# include <windows.h> - -int timespec_get(struct timespec *ts, int base) { -/* difference between 1970 and 1601 */ -# define _TIMESPEC_IMPL_UNIX_EPOCH_IN_TICKS 116444736000000000ull -/* 1 tick is 100 nanoseconds */ -# define _TIMESPEC_IMPL_TICKS_PER_SECONDS 10000000ull - if (ts == NULL) - return 0; - if (base == TIME_UTC) { - FILETIME ft; - ULARGE_INTEGER date; - LONGLONG ticks; - - GetSystemTimeAsFileTime(&ft); - date.HighPart = ft.dwHighDateTime; - date.LowPart = ft.dwLowDateTime; - ticks = (LONGLONG) (date.QuadPart - - _TIMESPEC_IMPL_UNIX_EPOCH_IN_TICKS); - ts->tv_sec = ticks / _TIMESPEC_IMPL_TICKS_PER_SECONDS; - ts->tv_nsec = (ticks % _TIMESPEC_IMPL_TICKS_PER_SECONDS) * 100; - return base; - } - return 0; -# undef _TIMESPEC_IMPL_UNIX_EPOCH_IN_TICKS -# undef _TIMESPEC_IMPL_TICKS_PER_SECONDS -} - -# elif defined(KIT_HAVE_CLOCK_GETTIME) -int timespec_get(struct timespec *ts, int base) { - if (ts == NULL) - return 0; - if (base == TIME_UTC) { - clock_gettime(CLOCK_REALTIME, ts); - return base; - } - return 0; -} -# else -# include <sys/time.h> - -int timespec_get(struct timespec *ts, int base) { - if (ts == NULL) - return 0; - if (base == TIME_UTC) { - struct timeval tv; - gettimeofday(&tv, NULL); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000; - return base; - } - return 0; -} -# endif - -#endif diff --git a/source/kit/time.h b/source/kit/time.h deleted file mode 100644 index cf54d47..0000000 --- a/source/kit/time.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef KIT_TIME_H -#define KIT_TIME_H - -#include <time.h> - -#ifndef TIME_UTC -# define TIME_UTC 1 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef KIT_NEED_STRUCT_TIMESPEC -# ifdef KIT_HAVE_BITS_TYPES_STRUCT_TIMESPEC_H -# include <bits/types/struct_timespec.h> -# else -struct timespec { - time_t tv_sec; /* Seconds - >= 0 */ - long tv_nsec; /* Nanoseconds - [0, 999999999] */ -}; -# endif -#endif - -#ifdef KIT_NEED_TIMESPEC_GET -int timespec_get(struct timespec *ts, int base); -#endif - -#ifdef __cplusplus -} -#endif - -#endif |