X-Git-Url: https://harrygodden.com/git/?p=fishladder.git;a=blobdiff_plain;f=vg%2Fvg_platform.h;fp=vg%2Fvg_platform.h;h=0000000000000000000000000000000000000000;hp=b1986b96d088e26732166a5020c6d6c2602e9d60;hb=30490c4c08d5c0f811017a901aa9e25a95be7c40;hpb=3363633178b1eea582304742ad1202487af0feb1 diff --git a/vg/vg_platform.h b/vg/vg_platform.h deleted file mode 100644 index b1986b9..0000000 --- a/vg/vg_platform.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef int8_t i8; -typedef int16_t i16; -typedef int32_t i32; -typedef int64_t i64; - -typedef unsigned int uint; - -typedef int v2i[2]; -typedef int v3i[3]; -typedef int v4i[4]; -typedef float v2f[2]; -typedef float v3f[3]; -typedef float v4f[4]; -typedef v2f m2x2f[2]; -typedef v3f m3x3f[3]; -typedef v3f m4x3f[4]; -typedef v3f boxf[2]; - -// Resource types -typedef struct vg_tex2d vg_tex2d; - -struct vg_achievement -{ - int is_set; - const char *name; -}; - -#define vg_static_assert _Static_assert - -#define vg_list_size( A ) (sizeof(A)/sizeof(A[0])) - -// THREADING -// ================================================================================================================== - -// Pthred emulation for windows -#ifdef _WIN32 - #include - #define MUTEX_TYPE HANDLE - #define MUTEX_INITIALIZER NULL - #define MUTEX_SETUP(x) (x) = CreateMutex(NULL, FALSE, NULL) - #define MUTEX_CLEANUP(x) (CloseHandle(x)) //TODO: Why is this defined but never used? - #define MUTEX_LOCK(x) emulate_pthread_mutex_lock(&(x)) - #define MUTEX_UNLOCK(x) (ReleaseMutex(x)) - - int emulate_pthread_mutex_lock( volatile MUTEX_TYPE *mx ) - { - if( *mx == NULL ) /* static initializer? */ - { - HANDLE p = CreateMutex( NULL, FALSE, NULL ); - if( InterlockedCompareExchangePointer( (PVOID*)mx, (PVOID)p, NULL ) != NULL ) - CloseHandle(p); - } - - return WaitForSingleObject( *mx, INFINITE ) == WAIT_FAILED; - } -#else - #include - #define MUTEX_LOCK(x) pthread_mutex_lock(&(x)) - #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x)) - #define MUTEX_TYPE pthread_mutex_t - #define MUTEX_INITIALIZER {0} -#endif - - -int vg_thread_run( void *pfunc, void *data ) -{ -#ifdef _WIN32 - - HANDLE hThread = CreateThread - ( - NULL, // Thread attributes - 0, // Stack size (0 = use default) - pfunc, // Thread start address - data, // Parameter to pass to the thread - 0, // Creation flags - NULL // Thread id - ); - - if ( hThread == NULL ) - { - // Thread creation failed. - // More details can be retrieved by calling GetLastError() - return 1; - } - else - { - CloseHandle( hThread ); - return 0; - } - -#else - - pthread_t hThread; - if( pthread_create( &hThread, NULL, pfunc, data ) ) - { - return 1; - } - else - { - pthread_detach( hThread ); - return 0; - } - -#endif -}