Betriebssystem.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. } // TODO dsfgdslgkjhlas
  50. // HACK dsgdshgah
  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. #endif
  80. #endif