24882841f007746d2d1642538fa904936f6bbda8
1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
12 typedef unsigned int uint
;
26 typedef struct vg_tex2d vg_tex2d
;
28 #define vg_static_assert _Static_assert
30 #define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))
33 // ==================================================================================================================
35 // Pthred emulation for windows
38 #define MUTEX_TYPE HANDLE
39 #define MUTEX_INITIALIZER NULL
40 #define MUTEX_SETUP(x) (x) = CreateMutex(NULL, FALSE, NULL)
41 #define MUTEX_CLEANUP(x) (CloseHandle(x)) //TODO: Why is this defined but never used?
42 #define MUTEX_LOCK(x) emulate_pthread_mutex_lock(&(x))
43 #define MUTEX_UNLOCK(x) (ReleaseMutex(x))
45 int emulate_pthread_mutex_lock( volatile MUTEX_TYPE
*mx
)
47 if( *mx
== NULL
) /* static initializer? */
49 HANDLE p
= CreateMutex( NULL
, FALSE
, NULL
);
50 if( InterlockedCompareExchangePointer( (PVOID
*)mx
, (PVOID
)p
, NULL
) != NULL
)
54 return WaitForSingleObject( *mx
, INFINITE
) == WAIT_FAILED
;
58 #define MUTEX_LOCK(x) pthread_mutex_lock(&(x))
59 #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x))
60 #define MUTEX_TYPE pthread_mutex_t
61 #define MUTEX_INITIALIZER {0}
65 int vg_thread_run( void *pfunc
, void *data
)
69 HANDLE hThread
= CreateThread
71 NULL
, // Thread attributes
72 0, // Stack size (0 = use default)
73 pfunc
, // Thread start address
74 data
, // Parameter to pass to the thread
79 if ( hThread
== NULL
)
81 // Thread creation failed.
82 // More details can be retrieved by calling GetLastError()
87 CloseHandle( hThread
);
94 if( pthread_create( &hThread
, NULL
, pfunc
, data
) )
100 pthread_detach( hThread
);