µGFX  2.9
version 2.9
gos_win32.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 /**
9  * @file src/gos/gos_win32.h
10  * @brief GOS - Operating System Support header file for WIN32.
11  */
12 
13 #ifndef _GOS_WIN32_H
14 #define _GOS_WIN32_H
15 
16 #if GFX_USE_OS_WIN32
17 
18 #ifndef _WIN32_WINNT
19  #define _WIN32_WINNT 0x0501 // Windows XP and up
20 #endif
21 
22 #define WIN32_LEAN_AND_MEAN
23 #include <windows.h>
24 #undef WIN32_LEAN_AND_MEAN
25 
26 #include <malloc.h>
27 
28 typedef DWORD gDelay;
29 typedef DWORD gTicks;
30 typedef LONG gSemcount;
31 typedef DWORD gThreadreturn;
32 typedef int gThreadpriority;
33 
34 #define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn (WINAPI fnName)(void *param)
35 #define GFX_THREAD_STACK(name, sz) gU8 name[1];
36 #define gfxThreadReturn(retval) return retval
37 
38 #define gDelayNone 0
39 #define gDelayForever INFINITE
40 #define gSemMaxCount ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
41 #define gThreadpriorityLow THREAD_PRIORITY_BELOW_NORMAL
42 #define gThreadpriorityNormal THREAD_PRIORITY_NORMAL
43 #define gThreadpriorityHigh THREAD_PRIORITY_ABOVE_NORMAL
44 
45 typedef HANDLE gSem;
46 typedef HANDLE gMutex;
47 typedef HANDLE gThread;
48 
49 #define gfxExit() ExitProcess(0)
50 #define gfxAlloc(sz) malloc(sz)
51 #define gfxRealloc(p,osz,nsz) realloc(p, nsz)
52 #define gfxFree(ptr) free(ptr)
53 #define gfxSleepMilliseconds(ms) Sleep(ms)
54 #define gfxYield() Sleep(0)
55 #define gfxSystemTicks() GetTickCount()
56 #define gfxMillisecondsToTicks(ms) (ms)
57 #define gfxMutexInit(pmutex) *(pmutex) = CreateMutex(0, FALSE, 0)
58 #define gfxMutexDestroy(pmutex) CloseHandle(*(pmutex))
59 #define gfxMutexEnter(pmutex) WaitForSingleObject(*(pmutex), INFINITE)
60 #define gfxMutexExit(pmutex) ReleaseMutex(*(pmutex))
61 #define gfxSemInit(psem, val, limit) *(psem) = CreateSemaphore(0, val, limit, 0)
62 #define gfxSemDestroy(psem) CloseHandle(*(psem))
63 #define gfxSemWaitI(psem) gfxSemWait((psem), gDelayNone)
64 #define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, 0)
65 #define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, 0)
66 #define gfxThreadMe() GetCurrentThread()
67 #define gfxThreadClose(thread) CloseHandle(thread)
68 
69 /*===========================================================================*/
70 /* Function declarations. */
71 /*===========================================================================*/
72 
73 void gfxHalt(const char *msg);
74 void gfxSleepMicroseconds(gDelay ms);
75 gBool gfxSemWait(gSem *psem, gDelay ms);
76 void gfxSystemLock(void);
77 void gfxSystemUnlock(void);
78 gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION(*fn,p), void *param);
79 gThreadreturn gfxThreadWait(gThread thread);
80 
81 #endif /* GFX_USE_OS_WIN32 */
82 #endif /* _GOS_WIN32_H */
83 
gThreadreturn gfxThreadWait(gThread thread)
Wait for a thread to finish.
void * gThread
A thread handle.
Definition: gos.h:116
#define GFX_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:73
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxSystemUnlock(void)
Unlock the operating system previous locked by gfxSystemLock()
void gfxSleepMicroseconds(gDelay us)
Put the current thread to sleep for the specified period in microseconds.
void gfxSystemLock(void)
Lock the operating system to protect a sequence of code.
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
void gfxHalt(const char *msg)
Halt the GFX application due to an error.
A mutex.
Definition: gos.h:110
A semaphore.
Definition: gos.h:104