Betriebssystem.h 2.0 KB

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