Betriebssystem.h 2.3 KB

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