mc 1.9
[vg.git] / src / vg / vg_platform.h
index b1986b96d088e26732166a5020c6d6c2602e9d60..02681d04d7ee832b0c21c03418f94287b1a6f655 100644 (file)
@@ -1,4 +1,4 @@
-// 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;
@@ -32,19 +32,17 @@ struct vg_achievement
 };
 
 #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))
 
@@ -53,7 +51,8 @@ struct vg_achievement
                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);
                }
                
@@ -71,21 +70,22 @@ struct vg_achievement
 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
@@ -93,9 +93,7 @@ int vg_thread_run( void *pfunc, void *data )
                CloseHandle( hThread );
                return 0;
        }
-       
 #else
-
        pthread_t hThread;
        if( pthread_create( &hThread, NULL, pfunc, data ) )
        {
@@ -106,6 +104,5 @@ int vg_thread_run( void *pfunc, void *data )
                pthread_detach( hThread );
                return 0;
        }
-
 #endif
 }