Betriebssystem.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include <string.h>
  35. #ifndef CRITICAL_SECTION_CLASS
  36. #define CRITICAL_SECTION_CLASS
  37. class CriticalSection
  38. {
  39. public:
  40. CriticalSection()
  41. {
  42. pthread_mutexattr_t attr;
  43. pthread_mutexattr_init( &attr );
  44. pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
  45. pthread_mutex_init( &mutex, &attr );
  46. } // TODO dsfgdslgkjhlas
  47. // HACK dsgdshgah
  48. ~CriticalSection()
  49. {
  50. pthread_mutex_destroy( &mutex );
  51. }
  52. void Enter()
  53. {
  54. pthread_mutex_lock( &mutex );
  55. }
  56. void Leave()
  57. {
  58. pthread_mutex_unlock( &mutex );
  59. }
  60. private:
  61. pthread_mutex_t mutex;
  62. };
  63. #else
  64. class CriticalSection;
  65. #endif
  66. #define CRITICAL_SECTION CriticalSection*
  67. #define InitializeCriticalSection( x ) ( *( x ) ) = new CriticalSection()
  68. #define DeleteCriticalSection( x ) delete ( *( x ) )
  69. #define EnterCriticalSection( x ) ( *( x ) )->Enter()
  70. #define LeaveCriticalSection( x ) ( *( x ) )->Leave()
  71. #include <unistd.h>
  72. #define Sleep( x ) usleep( (x) * 1000 )
  73. #define ZeroMemory( Destination, Length ) memset( ( Destination ), 0, ( Length ) )
  74. #endif
  75. #endif