1 /*
2     Copyright (c) 2005-2017 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 
18 
19 */
20 
21 #ifndef __TBB_machine_windows_api_H
22 #define __TBB_machine_windows_api_H
23 
24 #if _WIN32 || _WIN64
25 
26 #include <windows.h>
27 
28 #if _WIN32_WINNT < 0x0600
29 // The following Windows API function is declared explicitly;
30 // otherwise it fails to compile by VS2005.
31 #if !defined(WINBASEAPI) || (_WIN32_WINNT < 0x0501 && _MSC_VER == 1400)
32 #define __TBB_WINBASEAPI extern "C"
33 #else
34 #define __TBB_WINBASEAPI WINBASEAPI
35 #endif
36 __TBB_WINBASEAPI BOOL WINAPI TryEnterCriticalSection( LPCRITICAL_SECTION );
37 __TBB_WINBASEAPI BOOL WINAPI InitializeCriticalSectionAndSpinCount( LPCRITICAL_SECTION, DWORD );
38 // Overloading WINBASEAPI macro and using local functions missing in Windows XP/2003
39 #define InitializeCriticalSectionEx inlineInitializeCriticalSectionEx
40 #define CreateSemaphoreEx inlineCreateSemaphoreEx
41 #define CreateEventEx inlineCreateEventEx
inlineInitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection,DWORD dwSpinCount,DWORD)42 inline BOOL WINAPI inlineInitializeCriticalSectionEx( LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD )
43 {
44     return InitializeCriticalSectionAndSpinCount( lpCriticalSection, dwSpinCount );
45 }
inlineCreateSemaphoreEx(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,LONG lInitialCount,LONG lMaximumCount,LPCTSTR lpName,DWORD,DWORD)46 inline HANDLE WINAPI inlineCreateSemaphoreEx( LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName, DWORD, DWORD )
47 {
48     return CreateSemaphore( lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName );
49 }
inlineCreateEventEx(LPSECURITY_ATTRIBUTES lpEventAttributes,LPCTSTR lpName,DWORD dwFlags,DWORD)50 inline HANDLE WINAPI inlineCreateEventEx( LPSECURITY_ATTRIBUTES lpEventAttributes, LPCTSTR lpName, DWORD dwFlags, DWORD )
51 {
52     BOOL manual_reset = dwFlags&0x00000001 ? TRUE : FALSE; // CREATE_EVENT_MANUAL_RESET
53     BOOL initial_set  = dwFlags&0x00000002 ? TRUE : FALSE; // CREATE_EVENT_INITIAL_SET
54     return CreateEvent( lpEventAttributes, manual_reset, initial_set, lpName );
55 }
56 #endif
57 
58 #if defined(RTL_SRWLOCK_INIT)
59 #ifndef __TBB_USE_SRWLOCK
60 // TODO: turn it on when bug 1952 will be fixed
61 #define __TBB_USE_SRWLOCK 0
62 #endif
63 #endif
64 
65 #else
66 #error tbb/machine/windows_api.h should only be used for Windows based platforms
67 #endif // _WIN32 || _WIN64
68 
69 #endif // __TBB_machine_windows_api_H
70