aboutsummaryrefslogtreecommitdiffstats
path: root/src/gos/gos_win32.h
blob: 9c088bd9a285232f1583fda54dcb87a5138d3de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 */

/**
 * @file    src/gos/gos_win32.h
 * @brief   GOS - Operating System Support header file for WIN32.
 */

#ifndef _GOS_WIN32_H
#define _GOS_WIN32_H

#if GFX_USE_OS_WIN32

#ifndef _WIN32_WINNT
	#define _WIN32_WINNT 0x0501			// Windows XP and up
#endif

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN

#include <malloc.h>

typedef DWORD				gDelay;
typedef DWORD				gTicks;
typedef LONG				gSemcount;
typedef DWORD				gThreadreturn;
typedef int					gThreadpriority;

#define DECLARE_THREAD_FUNCTION(fnName, param)	gThreadreturn (WINAPI fnName)(void *param)
#define DECLARE_THREAD_STACK(name, sz)			uint8_t name[1];
#define THREAD_RETURN(retval)					return retval

#define gDelayNone					0
#define gDelayForever				INFINITE
#define MAX_SEMAPHORE_COUNT			((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
#define gThreadpriorityLow				THREAD_PRIORITY_BELOW_NORMAL
#define gThreadpriorityNormal				THREAD_PRIORITY_NORMAL
#define gThreadpriorityHigh				THREAD_PRIORITY_ABOVE_NORMAL

typedef HANDLE gfxSem;
typedef HANDLE gfxMutex;
typedef HANDLE gThread;

#define gfxExit()						ExitProcess(0)
#define gfxAlloc(sz)					malloc(sz)
#define gfxRealloc(p,osz,nsz)			realloc(p, nsz)
#define gfxFree(ptr)					free(ptr)
#define gfxSleepMilliseconds(ms)		Sleep(ms)
#define gfxYield()						Sleep(0)
#define gfxSystemTicks()				GetTickCount()
#define gfxMillisecondsToTicks(ms)		(ms)
#define gfxMutexInit(pmutex)			*(pmutex) = CreateMutex(0, FALSE, 0)
#define gfxMutexDestroy(pmutex)			CloseHandle(*(pmutex))
#define gfxMutexEnter(pmutex) 			WaitForSingleObject(*(pmutex), INFINITE)
#define gfxMutexExit(pmutex)			ReleaseMutex(*(pmutex))
#define gfxSemInit(psem, val, limit)	*(psem) = CreateSemaphore(0, val, limit, 0)
#define gfxSemDestroy(psem)				CloseHandle(*(psem))
#define gfxSemWaitI(psem)				gfxSemWait((psem), gDelayNone)
#define gfxSemSignal(psem)				ReleaseSemaphore(*(psem), 1, 0)
#define gfxSemSignalI(psem)				ReleaseSemaphore(*(psem), 1, 0)
#define gfxThreadMe()					GetCurrentThread()
#define gfxThreadClose(thread)			CloseHandle(thread)

/*===========================================================================*/
/* Function declarations.                                                    */
/*===========================================================================*/

void gfxHalt(const char *msg);
void gfxSleepMicroseconds(gDelay ms);
gBool gfxSemWait(gfxSem *psem, gDelay ms);
void gfxSystemLock(void);
void gfxSystemUnlock(void);
gThread gfxThreadCreate(void *stackarea, size_t stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION(*fn,p), void *param);
gThreadreturn gfxThreadWait(gThread thread);

#endif /* GFX_USE_OS_WIN32 */
#endif /* _GOS_WIN32_H */