Betriebssystem.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #define pthread_t void*
  23. #else
  24. #define __stdcall
  25. #define __declspec( x )
  26. #define __int64 long long
  27. #define __int32 int
  28. #define __int16 short
  29. #define __int8 char
  30. #define assert( x )
  31. #include <stdlib.h>
  32. #include <pthread.h>
  33. #include <stdio.h>
  34. #ifndef CRITICAL_SECTION_CLASS
  35. #define CRITICAL_SECTION_CLASS
  36. class CriticalSection
  37. {
  38. public:
  39. CriticalSection()
  40. {
  41. pthread_mutexattr_t attr;
  42. pthread_mutexattr_init( &attr );
  43. pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
  44. pthread_mutex_init( &mutex, &attr );
  45. }
  46. ~CriticalSection()
  47. {
  48. pthread_mutex_destroy( &mutex );
  49. }
  50. void Enter()
  51. {
  52. pthread_mutex_lock( &mutex );
  53. }
  54. void Leave()
  55. {
  56. pthread_mutex_unlock( &mutex );
  57. }
  58. private:
  59. pthread_mutex_t mutex;
  60. };
  61. #else
  62. class CriticalSection;
  63. #endif
  64. #define CRITICAL_SECTION CriticalSection*
  65. #define InitializeCriticalSection( x ) ( *( x ) ) = new CriticalSection()
  66. #define DeleteCriticalSection( x ) delete ( *( x ) )
  67. #define EnterCriticalSection( x ) ( *( x ) )->Enter()
  68. #define LeaveCriticalSection( x ) ( *( x ) )->Leave()
  69. #include <unistd.h>
  70. #define Sleep( x ) usleep( (x) * 1000 )
  71. #endif
  72. #endif