Betriebssystem.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #endif
  79. #endif