diff options
-rw-r--r-- | build_and_test.sh | 13 | ||||
-rw-r--r-- | source/kit/mutex.h | 7 | ||||
-rw-r--r-- | source/kit/thread.win32.c | 3 | ||||
-rw-r--r-- | source/kit/time.h | 38 | ||||
-rw-r--r-- | source/kit_test/shared.inl.h | 40 |
5 files changed, 82 insertions, 19 deletions
diff --git a/build_and_test.sh b/build_and_test.sh index 873bacf..7ed30c6 100644 --- a/build_and_test.sh +++ b/build_and_test.sh @@ -2,6 +2,7 @@ if [ ! -d "build" ]; then mkdir build fi +OS=Linux COMPILE=gcc COMPILEPP=g++ OBJ_POSTFIX=.o @@ -40,6 +41,7 @@ fi case $(uname | tr '[:upper:]' '[:lower:]') in *darwin*) + OS=macOS if [ "$2" = "" ]; then if command -v clang >/dev/null 2>&1; then echo "C compiler found - Clang" @@ -54,6 +56,7 @@ case $(uname | tr '[:upper:]' '[:lower:]') in fi ;; *msys*|*cygwin*|*mingw*|*nt*|*win*) + OS=Windows EXE_POSTFIX=.exe if [ "$2" = "" ]; then if command -v cl.exe >/dev/null 2>&1; then @@ -92,15 +95,15 @@ case $(uname | tr '[:upper:]' '[:lower:]') in ;; esac -echo "" - if [ "$COMPILE" = "gcc" ] || [ "$COMPILE" = "clang" ]; then if [ "$1" = "release" ]; then FLAGS="-O3" - elif [ "$COMPILE" = "gcc" ]; then + elif [ "$COMPILE" = "gcc" ] && [ "$OS" != "Windows" ]; then FLAGS="-O0 -fsanitize=undefined,address,leak" - else + elif [ "$OS" != "Windows" ]; then FLAGS="-O0 -fsanitize=undefined,address" + else + FLAGS="-O0" fi else if [ "$1" = "release" ]; then @@ -110,6 +113,8 @@ else fi fi +echo "" + $COMPILE ${FLAGS} \ ${FLAG_OBJ}"build/kit${OBJ_POSTFIX}" \ "source/kit/_static.c" diff --git a/source/kit/mutex.h b/source/kit/mutex.h index d427ea6..254d5fa 100644 --- a/source/kit/mutex.h +++ b/source/kit/mutex.h @@ -7,12 +7,7 @@ # endif # include "thread_defs.h" - -# include <time.h> - -# ifndef TIME_UTC -# define TIME_UTC 1 -# endif +# include "time.h" # if !defined(_WIN32) || defined(__CYGWIN__) # include <pthread.h> diff --git a/source/kit/thread.win32.c b/source/kit/thread.win32.c index f8542f7..c4b6f15 100644 --- a/source/kit/thread.win32.c +++ b/source/kit/thread.win32.c @@ -143,7 +143,8 @@ static void impl_tss_dtor_invoke(void) { int i; for (i = 0; i < EMULATED_THREADS_TSS_DTOR_SLOTNUM; i++) { if (impl_tss_dtor_tbl[i].dtor) { - void *val = (void *) (size_t) tss_get(impl_tss_dtor_tbl[i].key); + void *val = (void *) (size_t) TlsGetValue( + impl_tss_dtor_tbl[i].key); if (val) (impl_tss_dtor_tbl[i].dtor)(val); } diff --git a/source/kit/time.h b/source/kit/time.h new file mode 100644 index 0000000..af36211 --- /dev/null +++ b/source/kit/time.h @@ -0,0 +1,38 @@ +#ifndef KIT_TIME_H +#define KIT_TIME_H + +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif + +#include <time.h> + +#ifndef TIME_UTC +# define TIME_UTC 1 + +struct timespec { + time_t tv_sec; + long tv_nsec; +}; + +# if defined(_WIN32) && !defined(__CYGWIN__) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN 1 +# endif +# include <Windows.h> + +static int timespec_get(struct timespec *ts, int base) { + // TODO + // Windows implementation. + // +} +# else +static int timespec_get(struct timespec *ts, int base) { + // TODO + // Posix implementation. + // +} +# endif +#endif + +#endif diff --git a/source/kit_test/shared.inl.h b/source/kit_test/shared.inl.h index 90efcd3..f80f7ff 100644 --- a/source/kit_test/shared.inl.h +++ b/source/kit_test/shared.inl.h @@ -1,20 +1,44 @@ #ifndef KIT_TEST_SHARED_INL_H #define KIT_TEST_SHARED_INL_H -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif +// kit/time.h +// +#ifndef KIT_TIME_H +# define KIT_TIME_H + +# ifndef _GNU_SOURCE +# define _GNU_SOURCE +# endif + +# include <time.h> + +# ifndef TIME_UTC +# define TIME_UTC 1 + +struct timespec { + time_t tv_sec; + long tv_nsec; +}; + +# if defined(_WIN32) && !defined(__CYGWIN__) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN 1 +# endif +# include <Windows.h> + +static int timespec_get(struct timespec *ts, int base) { } +# else +static int timespec_get(struct timespec *ts, int base) { } +# endif +# endif + +#endif // kit/time.h #include <setjmp.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <time.h> - -#ifndef TIME_UTC -# define TIME_UTC 1 -#endif enum { white, blue, light, yellow, red, green }; |