Betriebssystem.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 __stdcall
  29. # define __declspec(x)
  30. # define __int64 long long
  31. # define __int32 int
  32. # define __int16 short
  33. # define __int8 char
  34. # define assert(x)
  35. # include <pthread.h>
  36. # include <stdio.h>
  37. # include <stdlib.h>
  38. # include <string.h>
  39. # ifndef CRITICAL_SECTION_CLASS
  40. # define CRITICAL_SECTION_CLASS
  41. class CriticalSection
  42. {
  43. public:
  44. CriticalSection()
  45. {
  46. pthread_mutexattr_t attr;
  47. pthread_mutexattr_init(&attr);
  48. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  49. pthread_mutex_init(&mutex, &attr);
  50. }
  51. ~CriticalSection()
  52. {
  53. pthread_mutex_destroy(&mutex);
  54. }
  55. void Enter()
  56. {
  57. pthread_mutex_lock(&mutex);
  58. }
  59. void Leave()
  60. {
  61. pthread_mutex_unlock(&mutex);
  62. }
  63. private:
  64. pthread_mutex_t mutex;
  65. };
  66. # else
  67. class CriticalSection;
  68. # endif
  69. # define GetCurrentThread pthread_self
  70. # define GetThreadId(x) x
  71. # define CRITICAL_SECTION CriticalSection*
  72. # define InitializeCriticalSection(x) (*(x)) = new CriticalSection()
  73. # define DeleteCriticalSection(x) delete (*(x))
  74. # define EnterCriticalSection(x) (*(x))->Enter()
  75. # define LeaveCriticalSection(x) (*(x))->Leave()
  76. # include <unistd.h>
  77. # define Sleep(x) usleep((x)*1000)
  78. # define ZeroMemory(Destination, Length) memset((Destination), 0, (Length))
  79. # define HINSTANCE void*
  80. # include <dlfcn.h>
  81. # define LoadLibrary(x) dlopen((x), RTLD_LAZY)
  82. # define GetProcAddress dlsym
  83. # define FreeLibrary dlclose
  84. #endif
  85. #define DLLEXPORT __declspec(dllexport)
  86. #endif