version 2.8
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.org/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 /* Stop cygwin from defining these types */
29 #define __int8_t_defined
30 
31 /**
32  * size_t
33  * TRUE, FALSE
34  * are already defined by Win32
35  */
36 typedef __int8 bool_t;
37 typedef __int8 int8_t;
38 typedef unsigned __int8 uint8_t;
39 typedef __int16 int16_t;
40 typedef unsigned __int16 uint16_t;
41 typedef __int32 int32_t;
42 typedef unsigned __int32 uint32_t;
43 typedef DWORD delaytime_t;
44 typedef DWORD systemticks_t;
45 typedef LONG semcount_t;
46 typedef DWORD threadreturn_t;
47 typedef int threadpriority_t;
48 
49 #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t (WINAPI fnName)(void *param)
50 #define DECLARE_THREAD_STACK(name, sz) uint8_t name[1];
51 #define THREAD_RETURN(retval) return retval
52 
53 #define TIME_IMMEDIATE 0
54 #define TIME_INFINITE INFINITE
55 #define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
56 #define LOW_PRIORITY THREAD_PRIORITY_BELOW_NORMAL
57 #define NORMAL_PRIORITY THREAD_PRIORITY_NORMAL
58 #define HIGH_PRIORITY THREAD_PRIORITY_ABOVE_NORMAL
59 
60 typedef HANDLE gfxSem;
61 typedef HANDLE gfxMutex;
62 typedef HANDLE gfxThreadHandle;
63 
64 #define gfxExit() ExitProcess(0)
65 #define gfxAlloc(sz) malloc(sz)
66 #define gfxRealloc(p,osz,nsz) realloc(p, nsz)
67 #define gfxFree(ptr) free(ptr)
68 #define gfxSleepMilliseconds(ms) Sleep(ms)
69 #define gfxYield() Sleep(0)
70 #define gfxSystemTicks() GetTickCount()
71 #define gfxMillisecondsToTicks(ms) (ms)
72 #define gfxMutexInit(pmutex) *(pmutex) = CreateMutex(0, FALSE, 0)
73 #define gfxMutexDestroy(pmutex) CloseHandle(*(pmutex))
74 #define gfxMutexEnter(pmutex) WaitForSingleObject(*(pmutex), INFINITE)
75 #define gfxMutexExit(pmutex) ReleaseMutex(*(pmutex))
76 #define gfxSemInit(psem, val, limit) *(psem) = CreateSemaphore(0, val, limit, 0)
77 #define gfxSemDestroy(psem) CloseHandle(*(psem))
78 #define gfxSemWaitI(psem) gfxSemWait((psem), TIME_IMMEDIATE)
79 #define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, 0)
80 #define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, 0)
81 #define gfxThreadMe() GetCurrentThread()
82 #define gfxThreadClose(thread) CloseHandle(thread)
83 
84 /*===========================================================================*/
85 /* Function declarations. */
86 /*===========================================================================*/
87 
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91 
92 void gfxHalt(const char *msg);
93 void gfxSleepMicroseconds(delaytime_t ms);
94 bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
95 void gfxSystemLock(void);
96 void gfxSystemUnlock(void);
97 gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION(*fn,p), void *param);
98 threadreturn_t gfxThreadWait(gfxThreadHandle thread);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* GFX_USE_OS_WIN32 */
105 #endif /* _GOS_WIN32_H */
106 
void * gfxThreadHandle
A thread handle.
Definition: gos.h:117
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
Wait on a semaphore.
A semaphore.
Definition: gos.h:105
void gfxSystemLock(void)
Lock the operating system to protect a sequence of code.
#define DECLARE_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:62
void gfxHalt(const char *msg)
Halt the GFX application due to an error.
void gfxSleepMicroseconds(delaytime_t us)
Put the current thread to sleep for the specified period in microseconds.
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
A mutex.
Definition: gos.h:111
threadreturn_t gfxThreadWait(gfxThreadHandle thread)
Wait for a thread to finish.
void gfxSystemUnlock(void)
Unlock the operating system previous locked by gfxSystemLock()