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