1 /* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
12 typedef unsigned int uint
;
22 typedef v3f m4x3f
[4]; /* TODO why this is 4x4 too? */
27 typedef struct vg_tex2d vg_tex2d
;
35 #define vg_static_assert _Static_assert
36 #define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))
38 /* Pthred emulation for windows */
41 #define MUTEX_TYPE HANDLE
42 #define MUTEX_INITIALIZER NULL
43 #define MUTEX_SETUP(x) (x) = CreateMutex(NULL, FALSE, NULL)
45 /* TODO: Why is this defined but never used? */
46 #define MUTEX_CLEANUP(x) (CloseHandle(x))
47 #define MUTEX_LOCK(x) emulate_pthread_mutex_lock(&(x))
48 #define MUTEX_UNLOCK(x) (ReleaseMutex(x))
50 int emulate_pthread_mutex_lock( volatile MUTEX_TYPE
*mx
)
52 if( *mx
== NULL
) /* static initializer? */
54 HANDLE p
= CreateMutex( NULL
, FALSE
, NULL
);
55 if( InterlockedCompareExchangePointer( (PVOID
*)mx
, (PVOID
)p
, NULL
)
60 return WaitForSingleObject( *mx
, INFINITE
) == WAIT_FAILED
;
64 #define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
65 #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
66 #define MUTEX_TYPE pthread_mutex_t
67 #define MUTEX_INITIALIZER {0}
71 int vg_thread_run( void *pfunc
, void *data
)
74 HANDLE hThread
= CreateThread
76 NULL
, /* Thread attributes */
77 0, /* Stack size (0 = use default) */
78 pfunc
, /* Thread start address */
79 data
, /* Parameter to pass to the thread */
80 0, /* Creation flags */
84 if ( hThread
== NULL
)
87 * Thread creation failed.
88 * More details can be retrieved by calling GetLastError()
94 CloseHandle( hThread
);
99 if( pthread_create( &hThread
, NULL
, pfunc
, data
) )
105 pthread_detach( hThread
);