Added platform detection macros and atomic/thread_local abstraction
This commit is contained in:
parent
c57e16db5a
commit
a696c2ba2b
|
@ -9,6 +9,7 @@
|
|||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
#include"platform.h"
|
||||
#include"win32_app.c"
|
||||
#include"debug_log.c"
|
||||
#include"memory.c"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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_
|
|
@ -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<stdatomic.h>
|
||||
#endif
|
||||
|
||||
#endif __ATOMIC_H_
|
|
@ -8,6 +8,7 @@
|
|||
*****************************************************************/
|
||||
#include<string.h> // 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()
|
||||
{
|
||||
|
|
|
@ -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<stdatomic.h>
|
||||
#endif
|
||||
|
||||
#include"atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
Loading…
Reference in New Issue