OperatingSystem.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef Betriebssystem_H
  2. #define Betriebssystem_H
  3. #define MAX_KNOCHEN_ANZ 128
  4. #define _NOHEAP
  5. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  6. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  7. #ifndef ROUND_UP
  8. # define ROUND_UP_POWER_OF_2(v, powerOf2Alignment) \
  9. (((v) + (powerOf2Alignment) - 1) & ~((powerOf2Alignment) - 1))
  10. #endif
  11. #ifdef _WIN32
  12. # ifdef _DEBUG
  13. # ifndef _NOHEAP
  14. # ifndef _LTMDB
  15. # define _CRTDBG_MAP_ALLOC
  16. # include <crtdbg.h>
  17. # include <stdlib.h>
  18. # define DEBUG_CLIENTBLOCK \
  19. new (_CLIENT_BLOCK, __FILE__, __LINE__)
  20. # define new DEBUG_CLIENTBLOCK
  21. # define _LTMDB
  22. # endif
  23. # endif
  24. # include <assert.h>
  25. # else
  26. # define assert(x)
  27. # endif
  28. # define WIN32_LEAN_AND_MEAN
  29. # include <Windows.h>
  30. # define pthread_t void*
  31. #else
  32. # define OUT
  33. # define __stdcall
  34. # define __declspec(x)
  35. # define __int64 long long
  36. # define __int32 int
  37. # define __int16 short
  38. # define __int8 char
  39. # define assert(x)
  40. # include <pthread.h>
  41. # include <stdio.h>
  42. # include <stdlib.h>
  43. # include <string.h>
  44. # ifndef CRITICAL_SECTION_CLASS
  45. # define CRITICAL_SECTION_CLASS
  46. class CriticalSection
  47. {
  48. public:
  49. CriticalSection()
  50. {
  51. pthread_mutexattr_t attr;
  52. pthread_mutexattr_init(&attr);
  53. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  54. pthread_mutex_init(&mutex, &attr);
  55. }
  56. ~CriticalSection()
  57. {
  58. pthread_mutex_destroy(&mutex);
  59. }
  60. void Enter()
  61. {
  62. pthread_mutex_lock(&mutex);
  63. }
  64. void Leave()
  65. {
  66. pthread_mutex_unlock(&mutex);
  67. }
  68. private:
  69. pthread_mutex_t mutex;
  70. };
  71. # else
  72. class CriticalSection;
  73. # endif
  74. # define GetCurrentThread pthread_self
  75. # define GetThreadId(x) x
  76. # define CRITICAL_SECTION CriticalSection*
  77. # define InitializeCriticalSection(x) (*(x)) = new CriticalSection()
  78. # define DeleteCriticalSection(x) delete (*(x))
  79. # define EnterCriticalSection(x) (*(x))->Enter()
  80. # define LeaveCriticalSection(x) (*(x))->Leave()
  81. # include <unistd.h>
  82. # define Sleep(x) usleep((x) * 1000)
  83. # define ZeroMemory(Destination, Length) memset((Destination), 0, (Length))
  84. # define HINSTANCE void*
  85. # include <dlfcn.h>
  86. # define LoadLibrary(x) dlopen((x), RTLD_LAZY)
  87. # define GetProcAddress dlsym
  88. # define FreeLibrary dlclose
  89. #endif
  90. #define DLLEXPORT __declspec(dllexport)
  91. #endif