µGFX library fork

gos_win32.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. * @file src/gos/gos_win32.h
  9. * @brief GOS - Operating System Support header file for WIN32.
  10. */
  11. #ifndef _GOS_WIN32_H
  12. #define _GOS_WIN32_H
  13. #if GFX_USE_OS_WIN32
  14. #ifndef _WIN32_WINNT
  15. #define _WIN32_WINNT 0x0501 // Windows XP and up
  16. #endif
  17. #define WIN32_LEAN_AND_MEAN
  18. #include <windows.h>
  19. #undef WIN32_LEAN_AND_MEAN
  20. #include <malloc.h>
  21. /* Stop cygwin from defining these types */
  22. #define __int8_t_defined
  23. /**
  24. * size_t
  25. * TRUE, FALSE
  26. * are already defined by Win32
  27. */
  28. typedef __int8 bool_t;
  29. typedef __int8 int8_t;
  30. typedef unsigned __int8 uint8_t;
  31. typedef __int16 int16_t;
  32. typedef unsigned __int16 uint16_t;
  33. typedef __int32 int32_t;
  34. typedef unsigned __int32 uint32_t;
  35. typedef DWORD delaytime_t;
  36. typedef DWORD systemticks_t;
  37. typedef LONG semcount_t;
  38. typedef DWORD threadreturn_t;
  39. typedef int threadpriority_t;
  40. #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t (WINAPI fnName)(void *param)
  41. #define DECLARE_THREAD_STACK(name, sz) uint8_t name[1];
  42. #define THREAD_RETURN(retval) return retval
  43. #define TIME_IMMEDIATE 0
  44. #define TIME_INFINITE INFINITE
  45. #define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
  46. #define LOW_PRIORITY THREAD_PRIORITY_BELOW_NORMAL
  47. #define NORMAL_PRIORITY THREAD_PRIORITY_NORMAL
  48. #define HIGH_PRIORITY THREAD_PRIORITY_ABOVE_NORMAL
  49. typedef HANDLE gfxSem;
  50. typedef HANDLE gfxMutex;
  51. typedef HANDLE gfxThreadHandle;
  52. #define gfxExit() ExitProcess(0)
  53. #define gfxAlloc(sz) malloc(sz)
  54. #define gfxRealloc(p,osz,nsz) realloc(p, nsz)
  55. #define gfxFree(ptr) free(ptr)
  56. #define gfxSleepMilliseconds(ms) Sleep(ms)
  57. #define gfxYield() Sleep(0)
  58. #define gfxSystemTicks() GetTickCount()
  59. #define gfxMillisecondsToTicks(ms) (ms)
  60. #define gfxMutexInit(pmutex) *(pmutex) = CreateMutex(0, FALSE, 0)
  61. #define gfxMutexDestroy(pmutex) CloseHandle(*(pmutex))
  62. #define gfxMutexEnter(pmutex) WaitForSingleObject(*(pmutex), INFINITE)
  63. #define gfxMutexExit(pmutex) ReleaseMutex(*(pmutex))
  64. #define gfxSemInit(psem, val, limit) *(psem) = CreateSemaphore(0, val, limit, 0)
  65. #define gfxSemDestroy(psem) CloseHandle(*(psem))
  66. #define gfxSemWaitI(psem) gfxSemWait((psem), TIME_IMMEDIATE)
  67. #define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, 0)
  68. #define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, 0)
  69. #define gfxSemCounterI(psem) gfxSemCounter(psem)
  70. #define gfxThreadMe() GetCurrentThread()
  71. #define gfxThreadClose(thread) CloseHandle(thread)
  72. /*===========================================================================*/
  73. /* Function declarations. */
  74. /*===========================================================================*/
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78. void gfxHalt(const char *msg);
  79. void gfxSleepMicroseconds(delaytime_t ms);
  80. bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
  81. semcount_t gfxSemCounter(gfxSem *pSem);
  82. void gfxSystemLock(void);
  83. void gfxSystemUnlock(void);
  84. gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION(*fn,p), void *param);
  85. threadreturn_t gfxThreadWait(gfxThreadHandle thread);
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89. #endif /* GFX_USE_OS_WIN32 */
  90. #endif /* _GOS_WIN32_H */