diff --git a/examples/simpleWindow/main.c b/examples/simpleWindow/main.c index 0eac4f4..e29bb6e 100644 --- a/examples/simpleWindow/main.c +++ b/examples/simpleWindow/main.c @@ -9,6 +9,7 @@ #include #include +#include"platform.h" #include"win32_app.c" #include"debug_log.c" #include"memory.c" diff --git a/src/milepost.m b/src/milepost.m index bce8ec4..dd61be8 100644 --- a/src/milepost.m +++ b/src/milepost.m @@ -7,12 +7,6 @@ * *****************************************************************/ -#ifdef _WIN32 - -#include"win32_app.c" - -#else - #include"osx_app.m" #include"metal_surface.m" #include"metal_painter.m" @@ -23,5 +17,3 @@ #pragma clang diagnostic pop #include"osx_surface_client.m" - -#endif diff --git a/src/platform/platform.h b/src/platform/platform.h new file mode 100644 index 0000000..23c90c7 --- /dev/null +++ b/src/platform/platform.h @@ -0,0 +1,85 @@ +//***************************************************************** +// +// $file: platform.h $ +// $author: Martin Fouilleul $ +// $date: 22/12/2022 $ +// $revision: $ +// $note: (C) 2022 by Martin Fouilleul - all rights reserved $ +// +//***************************************************************** +#ifndef __PLATFORM_H_ +#define __PLATFORM_H_ + +//----------------------------------------------------------------- +// Compiler identification +//----------------------------------------------------------------- +#if defined(__clang__) + #define COMPILER_CLANG 1 + #if defined(__apple_build_version__) + #define COMPILER_CLANG_APPLE 1 + #elif defined(_MSC_VER) + #define COMPILER_CLANG_CL 1 + #endif + +#elif defined(_MSC_VER) + #define COMPILER_CL 1 +#elif defined(__GNUC__) + #define COMPILER_GCC 1 +#else + #error "Can't identify compiler" +#endif + +//----------------------------------------------------------------- +// OS identification +//----------------------------------------------------------------- +#if defined(_WIN64) + #define OS_WIN64 1 +#elif defined(_WIN32) + #error "Unsupported OS (32bit only version of Windows)" +#elif defined(__APPLE__) && defined(__MACH__) + #define OS_MACOS 1 +#elif defined(__gnu_linux__) + #define OS_LINUX 1 +#else + #error "Can't identify OS" +#endif + +//----------------------------------------------------------------- +// Architecture identification +//----------------------------------------------------------------- +#if defined(COMPILER_CL) + #if defined(_M_AMD64) + #define ARCH_X64 1 + #elif defined(_M_I86) + #define ARCH_X86 1 + #elif defined(_M_ARM64) + #define ARCH_ARM64 1 + #elif defined(_M_ARM) + #define ARCH_ARM32 1 + #else + #error "Can't identify architecture" + #endif +#else + #if defined(__x86_64__) + #define ARCH_X64 1 + #elif defined(__i386__) + #define ARCH_X86 1 + #elif defined(__arm__) + #define ARCH_ARM32 1 + #elif defined(__aarch64__) + #define ARCH_ARM64 1 + #else + #error "Can't identify architecture" + #endif +#endif + +//----------------------------------------------------------------- +// platform helper macros +//----------------------------------------------------------------- +#if defined(COMPILER_CL) + #define mp_thread_local __declspec(thread) +#elif defined(COMPILER_GCC) || defined(COMPILER_CLANG) + #define mp_thread_local __thread +#endif + +#endif // __PLATFORM_H_ diff --git a/src/util/atomic.h b/src/util/atomic.h new file mode 100644 index 0000000..580e50b --- /dev/null +++ b/src/util/atomic.h @@ -0,0 +1,22 @@ +//***************************************************************** +// +// $file: atomic.h $ +// $author: Martin Fouilleul $ +// $date: 22/12/2022 $ +// $revision: $ +// $note: (C) 2022 by Martin Fouilleul - all rights reserved $ +// +//***************************************************************** +#ifndef __ATOMIC_H_ +#define __ATOMIC_H_ + +#include"platform.h" + +#if (defined(COMPILER_CL) || defined(COMPILER_CLANG_CL)) && defined(__STDC_NO_ATOMICS__) + #define _Atomic(t) volatile t + //TODO +#else + #include +#endif + +#endif __ATOMIC_H_ diff --git a/src/util/memory.c b/src/util/memory.c index 4136d2b..093f5ad 100644 --- a/src/util/memory.c +++ b/src/util/memory.c @@ -8,6 +8,7 @@ *****************************************************************/ #include // memset +#include"platform.h" #include"memory.h" #include"platform_base_allocator.h" #include"macro_helpers.h" @@ -112,13 +113,7 @@ void mem_pool_clear(mem_pool* pool) //NOTE(martin): per-thread scratch arena //-------------------------------------------------------------------------------- -//TODO: move that somewhere in context cracking code -#ifdef _WIN32 - #define __thread __declspec(thread) -#endif - -__thread mem_arena __scratchArena = {0}; - +mp_thread_local mem_arena __scratchArena = {0}; mem_arena* mem_scratch() { diff --git a/src/util/ringbuffer.h b/src/util/ringbuffer.h index e5f5a7d..b9f7c1f 100644 --- a/src/util/ringbuffer.h +++ b/src/util/ringbuffer.h @@ -10,13 +10,7 @@ #define __RINGBUFFER_H_ #include"typedefs.h" - -#if defined(_MSC_VER) && defined(__STDC_NO_ATOMICS__) - #define _Atomic(t) volatile t -#else - #include -#endif - +#include"atomic.h" #ifdef __cplusplus extern "C" {