OperatingSystem.h 2.4 KB

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