windows_api.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Copyright (c) 2005-2020 Intel Corporation
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #ifndef __TBB_machine_windows_api_H
  14. #define __TBB_machine_windows_api_H
  15. #if _WIN32 || _WIN64
  16. #include <windows.h>
  17. #if _WIN32_WINNT < 0x0600
  18. // The following Windows API function is declared explicitly;
  19. // otherwise it fails to compile by VS2005.
  20. #if !defined(WINBASEAPI) || (_WIN32_WINNT < 0x0501 && _MSC_VER == 1400)
  21. #define __TBB_WINBASEAPI extern "C"
  22. #else
  23. #define __TBB_WINBASEAPI WINBASEAPI
  24. #endif
  25. __TBB_WINBASEAPI BOOL WINAPI TryEnterCriticalSection( LPCRITICAL_SECTION );
  26. __TBB_WINBASEAPI BOOL WINAPI InitializeCriticalSectionAndSpinCount( LPCRITICAL_SECTION, DWORD );
  27. // Overloading WINBASEAPI macro and using local functions missing in Windows XP/2003
  28. #define InitializeCriticalSectionEx inlineInitializeCriticalSectionEx
  29. #define CreateSemaphoreEx inlineCreateSemaphoreEx
  30. #define CreateEventEx inlineCreateEventEx
  31. inline BOOL WINAPI inlineInitializeCriticalSectionEx( LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD )
  32. {
  33. return InitializeCriticalSectionAndSpinCount( lpCriticalSection, dwSpinCount );
  34. }
  35. inline HANDLE WINAPI inlineCreateSemaphoreEx( LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName, DWORD, DWORD )
  36. {
  37. return CreateSemaphore( lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName );
  38. }
  39. inline HANDLE WINAPI inlineCreateEventEx( LPSECURITY_ATTRIBUTES lpEventAttributes, LPCTSTR lpName, DWORD dwFlags, DWORD )
  40. {
  41. BOOL manual_reset = dwFlags&0x00000001 ? TRUE : FALSE; // CREATE_EVENT_MANUAL_RESET
  42. BOOL initial_set = dwFlags&0x00000002 ? TRUE : FALSE; // CREATE_EVENT_INITIAL_SET
  43. return CreateEvent( lpEventAttributes, manual_reset, initial_set, lpName );
  44. }
  45. #endif
  46. #if defined(RTL_SRWLOCK_INIT)
  47. #ifndef __TBB_USE_SRWLOCK
  48. // TODO: turn it on when bug 1952 will be fixed
  49. #define __TBB_USE_SRWLOCK 0
  50. #endif
  51. #endif
  52. #else
  53. #error tbb/machine/windows_api.h should only be used for Windows based platforms
  54. #endif // _WIN32 || _WIN64
  55. #endif // __TBB_machine_windows_api_H