1 #pragma once 2 #ifndef __LGE_SYSTEM_H__ 3 #define __LGE_SYSTEM_H__ 4 5 #ifdef _WIN32 6 7 #include <windows.h> 8 typedef DWORD THREAD_RET; 9 #define THRAPI __stdcall 10 #include <stdint.h> 11 12 #else //_WIN32 13 14 #include <stdint.h> 15 #include <pthread.h> 16 17 typedef void * THREAD_RET; 18 typedef THREAD_RET (*PTHREAD_START_ROUTINE)(void *lpThreadParameter); 19 typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE; 20 21 typedef pthread_mutex_t CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION; 22 23 #define THRAPI 24 25 #ifndef FALSE 26 #define FALSE 0 27 #endif 28 29 #ifndef TRUE 30 #define TRUE 1 31 #endif 32 33 typedef void * HANDLE; 34 #define MAXIMUM_WAIT_OBJECTS 64 35 #define INFINITE (-1) 36 #define WAIT_FAILED (-1) 37 #define WAIT_TIMEOUT 0x102 38 #define WAIT_OBJECT 0 39 #define WAIT_OBJECT_0 0 40 #define WAIT_ABANDONED 128 41 #define WAIT_ABANDONED_0 128 42 43 #ifdef __cplusplus 44 extern "C" { 45 #else 46 #ifndef bool 47 #define bool int 48 #endif 49 #endif 50 51 HANDLE event_create(bool manualReset 52 #ifdef __cplusplus 53 = false 54 #endif 55 , bool initialState 56 #ifdef __cplusplus 57 = false 58 #endif 59 ); 60 bool event_set(HANDLE event); 61 bool event_reset(HANDLE event); 62 int event_wait(HANDLE event, uint32_t milliseconds 63 #ifdef __cplusplus 64 = INFINITE 65 #endif 66 ); 67 int event_wait_multiple(uint32_t count, const HANDLE *events, bool waitAll 68 #ifdef __cplusplus 69 = false 70 #endif 71 , uint32_t milliseconds 72 #ifdef __cplusplus 73 = INFINITE 74 #endif 75 ); 76 77 bool InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection); 78 bool DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection); 79 bool EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection); 80 bool LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection); 81 82 HANDLE thread_create(LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter); 83 84 #ifdef __cplusplus 85 } 86 #endif 87 88 #endif //_WIN32 89 90 #ifdef __cplusplus 91 extern "C" { 92 #endif 93 94 bool event_destroy(HANDLE event); 95 96 bool thread_close(HANDLE thread); 97 void *thread_wait(HANDLE thread); 98 bool thread_name(const char *name); 99 void thread_sleep(uint32_t milliseconds); 100 101 uint64_t GetTime(); 102 103 #ifdef __cplusplus 104 } 105 #endif 106 107 #endif //__LGE_SYSTEM_H__ 108