7e70d81178a9cdb8599165d0249645e3563ac8f8
4 /* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
15 typedef unsigned int uint
;
25 typedef v3f m4x3f
[4]; /* TODO why this is 4x4 too? */
30 typedef struct vg_tex2d vg_tex2d
;
38 #define vg_static_assert _Static_assert
39 #define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))
41 /* Pthred emulation for windows */
44 #define MUTEX_TYPE HANDLE
45 #define MUTEX_INITIALIZER NULL
46 #define MUTEX_SETUP(x) (x) = CreateMutex(NULL, FALSE, NULL)
48 /* TODO: Why is this defined but never used? */
49 #define MUTEX_CLEANUP(x) (CloseHandle(x))
50 #define MUTEX_LOCK(x) emulate_pthread_mutex_lock(&(x))
51 #define MUTEX_UNLOCK(x) (ReleaseMutex(x))
53 int emulate_pthread_mutex_lock( volatile MUTEX_TYPE
*mx
)
55 if( *mx
== NULL
) /* static initializer? */
57 HANDLE p
= CreateMutex( NULL
, FALSE
, NULL
);
58 if( InterlockedCompareExchangePointer( (PVOID
*)mx
, (PVOID
)p
, NULL
)
63 return WaitForSingleObject( *mx
, INFINITE
) == WAIT_FAILED
;
67 #define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
68 #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
69 #define MUTEX_TYPE pthread_mutex_t
70 #define MUTEX_INITIALIZER {0}
74 int vg_thread_run( void *pfunc
, void *data
)
77 HANDLE hThread
= CreateThread
79 NULL
, /* Thread attributes */
80 0, /* Stack size (0 = use default) */
81 pfunc
, /* Thread start address */
82 data
, /* Parameter to pass to the thread */
83 0, /* Creation flags */
87 if ( hThread
== NULL
)
90 * Thread creation failed.
91 * More details can be retrieved by calling GetLastError()
97 CloseHandle( hThread
);
102 if( pthread_create( &hThread
, NULL
, pfunc
, data
) )
108 pthread_detach( hThread
);