-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
typedef uint8_t u8;
typedef uint16_t u16;
};
#define vg_static_assert _Static_assert
-
#define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))
-// THREADING
-// ==================================================================================================================
-
-// Pthred emulation for windows
+/* Pthred emulation for windows */
#ifdef _WIN32
#include <windows.h>
#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?
+
+ /* TODO: Why is this defined but never used? */
+ #define MUTEX_CLEANUP(x) (CloseHandle(x))
#define MUTEX_LOCK(x) emulate_pthread_mutex_lock(&(x))
#define MUTEX_UNLOCK(x) (ReleaseMutex(x))
if( *mx == NULL ) /* static initializer? */
{
HANDLE p = CreateMutex( NULL, FALSE, NULL );
- if( InterlockedCompareExchangePointer( (PVOID*)mx, (PVOID)p, NULL ) != NULL )
+ if( InterlockedCompareExchangePointer( (PVOID*)mx, (PVOID)p, NULL )
+ != NULL )
CloseHandle(p);
}
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
+ 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()
+ /*
+ * 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 ) )
{
pthread_detach( hThread );
return 0;
}
-
#endif
}