From 8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 26 May 2013 02:06:55 +1000 Subject: More GOS module changes GQUEUE as a seperate module GOS changes including basic Win32 O/S support --- src/gos/win32.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) (limited to 'src/gos/win32.c') diff --git a/src/gos/win32.c b/src/gos/win32.c index 6cf803a2..bda57f6f 100644 --- a/src/gos/win32.c +++ b/src/gos/win32.c @@ -26,7 +26,86 @@ #if GFX_USE_OS_WIN32 -#error "GOS: WIN32 not supported yet" +#include + +static HANDLE SystemMutex; + +void _gosInit(void) { +} + +void gfxHalt(const char *msg) { + fprintf(stderr, "%s\n", msg); + ExitProcess(1); +} + +void gfxSleepMicroseconds(delaytime_t ms) { + static LARGE_INTEGER pcfreq; + static int initflag; + LARGE_INTEGER t1, t2, tdiff; + + switch(ms) { + case TIME_IMMEDIATE: return; + case TIME_INFINITE: while(1) Sleep(1000); return; + } + + if (!initflag) { + QueryPerformanceFrequency(&pcfreq); + initflag++; + } + tdiff.QuadPart = pcfreq.QuadPart * ms / 1000000; + + QueryPerformanceCounter(&t1); + do { + QueryPerformanceCounter(&t2); + } while (t2.QuadPart - t1.QuadPart < tdiff.QuadPart); +} + +void gfxSystemLock(void) { + if (!SystemMutex) + SystemMutex = CreateMutex(NULL, FALSE, NULL); + WaitForSingleObject(SystemMutex, INFINITE); +} + +void gfxSystemUnlock(void) { + ReleaseMutex(SystemMutex); +} + +bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) { + return WaitForSingleObject(*psem, ms) == WAIT_OBJECT_0; +} + +typedef LONG __stdcall (*_NtQuerySemaphore)( + HANDLE SemaphoreHandle, + DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */ + PVOID SemaphoreInformation, /* but this is to much to dump here */ + ULONG SemaphoreInformationLength, + PULONG ReturnLength OPTIONAL +); + +semcount_t gfxSemCounter(gfxSem *pSem) { + static _NtQuerySemaphore NtQuerySemaphore; + struct _SEMAPHORE_BASIC_INFORMATION { + ULONG CurrentCount; + ULONG MaximumCount; + } BasicInfo; + + if (!NtQuerySemaphore) + NtQuerySemaphore = (_NtQuerySemaphore)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySemaphore"); + + NtQuerySemaphore(*pSem, 0, &BasicInfo, sizeof(BasicInfo), NULL); + return BasicInfo.CurrentCount; +} + +bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param) { + (void) stackarea; + HANDLE thd; + + if (!(thd = CreateThread(NULL, stacksz, fn, param, CREATE_SUSPENDED, NULL))) + return FALSE; + SetThreadPriority(thd, prio); + ResumeThread(thd); + return TRUE; +} #endif /* GFX_USE_OS_WIN32 */ /** @} */ -- cgit v1.2.3