synchronization.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // synchronizaion.hpp --------------------------------------------------------------//
  2. // Copyright 2010 Vicente J. Botet Escriba
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. #ifndef BOOST_DETAIL_WINAPI_SYNCHRONIZATION_HPP
  6. #define BOOST_DETAIL_WINAPI_SYNCHRONIZATION_HPP
  7. #include <boost/detail/winapi/basic_types.hpp>
  8. #ifdef BOOST_HAS_PRAGMA_ONCE
  9. #pragma once
  10. #endif
  11. namespace boost
  12. {
  13. namespace detail
  14. {
  15. namespace winapi
  16. {
  17. #if defined( BOOST_USE_WINDOWS_H )
  18. typedef ::CRITICAL_SECTION CRITICAL_SECTION_;
  19. typedef ::PAPCFUNC PAPCFUNC_;
  20. using ::InitializeCriticalSection;
  21. using ::EnterCriticalSection;
  22. using ::TryEnterCriticalSection;
  23. using ::LeaveCriticalSection;
  24. using ::DeleteCriticalSection;
  25. # ifdef BOOST_NO_ANSI_APIS
  26. using ::CreateMutexW;
  27. using ::CreateEventW;
  28. using ::OpenEventW;
  29. using ::CreateSemaphoreW;
  30. # else
  31. using ::CreateMutexA;
  32. using ::CreateEventA;
  33. using ::OpenEventA;
  34. using ::CreateSemaphoreA;
  35. # endif
  36. using ::ReleaseMutex;
  37. using ::ReleaseSemaphore;
  38. using ::SetEvent;
  39. using ::ResetEvent;
  40. using ::WaitForMultipleObjects;
  41. using ::WaitForSingleObject;
  42. using ::QueueUserAPC;
  43. const DWORD_ infinite = INFINITE;
  44. const DWORD_ wait_abandoned = WAIT_ABANDONED;
  45. const DWORD_ wait_object_0 = WAIT_OBJECT_0;
  46. const DWORD_ wait_timeout = WAIT_TIMEOUT;
  47. const DWORD_ wait_failed = WAIT_FAILED;
  48. #else // defined( BOOST_USE_WINDOWS_H )
  49. extern "C" {
  50. struct CRITICAL_SECTION_
  51. {
  52. struct critical_section_debug * DebugInfo;
  53. long LockCount;
  54. long RecursionCount;
  55. void * OwningThread;
  56. void * LockSemaphore;
  57. #if defined(_WIN64)
  58. unsigned __int64 SpinCount;
  59. #else
  60. unsigned long SpinCount;
  61. #endif
  62. };
  63. __declspec(dllimport) void __stdcall
  64. InitializeCriticalSection(CRITICAL_SECTION_ *);
  65. __declspec(dllimport) void __stdcall
  66. EnterCriticalSection(CRITICAL_SECTION_ *);
  67. __declspec(dllimport) bool __stdcall
  68. TryEnterCriticalSection(CRITICAL_SECTION_ *);
  69. __declspec(dllimport) void __stdcall
  70. LeaveCriticalSection(CRITICAL_SECTION_ *);
  71. __declspec(dllimport) void __stdcall
  72. DeleteCriticalSection(CRITICAL_SECTION_ *);
  73. struct _SECURITY_ATTRIBUTES;
  74. # ifdef BOOST_NO_ANSI_APIS
  75. __declspec(dllimport) void* __stdcall
  76. CreateMutexW(_SECURITY_ATTRIBUTES*,int,wchar_t const*);
  77. __declspec(dllimport) void* __stdcall
  78. CreateSemaphoreW(_SECURITY_ATTRIBUTES*,long,long,wchar_t const*);
  79. __declspec(dllimport) void* __stdcall
  80. CreateEventW(_SECURITY_ATTRIBUTES*,int,int,wchar_t const*);
  81. __declspec(dllimport) void* __stdcall
  82. OpenEventW(unsigned long,int,wchar_t const*);
  83. # else
  84. __declspec(dllimport) void* __stdcall
  85. CreateMutexA(_SECURITY_ATTRIBUTES*,int,char const*);
  86. __declspec(dllimport) void* __stdcall
  87. CreateSemaphoreA(_SECURITY_ATTRIBUTES*,long,long,char const*);
  88. __declspec(dllimport) void* __stdcall
  89. CreateEventA(_SECURITY_ATTRIBUTES*,int,int,char const*);
  90. __declspec(dllimport) void* __stdcall
  91. OpenEventA(unsigned long,int,char const*);
  92. # endif
  93. __declspec(dllimport) int __stdcall
  94. ReleaseMutex(void*);
  95. __declspec(dllimport) unsigned long __stdcall
  96. WaitForSingleObject(void*,unsigned long);
  97. __declspec(dllimport) unsigned long __stdcall
  98. WaitForMultipleObjects(unsigned long nCount,
  99. void* const * lpHandles,
  100. int bWaitAll,
  101. unsigned long dwMilliseconds);
  102. __declspec(dllimport) int __stdcall
  103. ReleaseSemaphore(void*,long,long*);
  104. typedef void (__stdcall *PAPCFUNC8)(ULONG_PTR_);
  105. __declspec(dllimport) unsigned long __stdcall
  106. QueueUserAPC(PAPCFUNC8,void*,ULONG_PTR_);
  107. # ifndef UNDER_CE
  108. __declspec(dllimport) int __stdcall
  109. SetEvent(void*);
  110. __declspec(dllimport) int __stdcall
  111. ResetEvent(void*);
  112. # else
  113. using ::SetEvent;
  114. using ::ResetEvent;
  115. # endif
  116. } // extern "C"
  117. const DWORD_ infinite = (DWORD_)0xFFFFFFFF;
  118. const DWORD_ wait_abandoned = 0x00000080L;
  119. const DWORD_ wait_object_0 = 0x00000000L;
  120. const DWORD_ wait_timeout = 0x00000102L;
  121. const DWORD_ wait_failed = (DWORD_)0xFFFFFFFF;
  122. #endif // defined( BOOST_USE_WINDOWS_H )
  123. }
  124. }
  125. }
  126. #endif // BOOST_DETAIL_WINAPI_SYNCHRONIZATION_HPP