Betriebssystem.h 1.7 KB

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