BRE12
windows_api.h
1 /*
2  Copyright 2005-2016 Intel Corporation. All Rights Reserved.
3 
4  This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5  you can redistribute it and/or modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation. Threading Building Blocks is
7  distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9  See the GNU General Public License for more details. You should have received a copy of
10  the GNU General Public License along with Threading Building Blocks; if not, write to the
11  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12 
13  As a special exception, you may use this file as part of a free software library without
14  restriction. Specifically, if other files instantiate templates or use macros or inline
15  functions from this file, or you compile this file and link it with other files to produce
16  an executable, this file does not by itself cause the resulting executable to be covered
17  by the GNU General Public License. This exception does not however invalidate any other
18  reasons why the executable file might be covered by the GNU General Public License.
19 */
20 
21 #ifndef __TBB_machine_windows_api_H
22 #define __TBB_machine_windows_api_H
23 
24 #if _WIN32 || _WIN64
25 
26 #if _XBOX
27 
28 #define NONET
29 #define NOD3D
30 #include <xtl.h>
31 
32 #else // Assume "usual" Windows
33 
34 #include <windows.h>
35 
36 #endif // _XBOX
37 
38 #if _WIN32_WINNT < 0x0600
39 // The following Windows API function is declared explicitly;
40 // otherwise it fails to compile by VS2005.
41 #if !defined(WINBASEAPI) || (_WIN32_WINNT < 0x0501 && _MSC_VER == 1400)
42 #define __TBB_WINBASEAPI extern "C"
43 #else
44 #define __TBB_WINBASEAPI WINBASEAPI
45 #endif
46 __TBB_WINBASEAPI BOOL WINAPI TryEnterCriticalSection( LPCRITICAL_SECTION );
47 __TBB_WINBASEAPI BOOL WINAPI InitializeCriticalSectionAndSpinCount( LPCRITICAL_SECTION, DWORD );
48 // Overloading WINBASEAPI macro and using local functions missing in Windows XP/2003
49 #define InitializeCriticalSectionEx inlineInitializeCriticalSectionEx
50 #define CreateSemaphoreEx inlineCreateSemaphoreEx
51 #define CreateEventEx inlineCreateEventEx
52 inline BOOL WINAPI inlineInitializeCriticalSectionEx( LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD )
53 {
54  return InitializeCriticalSectionAndSpinCount( lpCriticalSection, dwSpinCount );
55 }
56 inline HANDLE WINAPI inlineCreateSemaphoreEx( LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCTSTR lpName, DWORD, DWORD )
57 {
58  return CreateSemaphore( lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName );
59 }
60 inline HANDLE WINAPI inlineCreateEventEx( LPSECURITY_ATTRIBUTES lpEventAttributes, LPCTSTR lpName, DWORD dwFlags, DWORD )
61 {
62  BOOL manual_reset = dwFlags&0x00000001 ? TRUE : FALSE; // CREATE_EVENT_MANUAL_RESET
63  BOOL initial_set = dwFlags&0x00000002 ? TRUE : FALSE; // CREATE_EVENT_INITIAL_SET
64  return CreateEvent( lpEventAttributes, manual_reset, initial_set, lpName );
65 }
66 #endif
67 
68 #if defined(RTL_SRWLOCK_INIT)
69 #ifndef __TBB_USE_SRWLOCK
70 // TODO: turn it on when bug 1952 will be fixed
71 #define __TBB_USE_SRWLOCK 0
72 #endif
73 #endif
74 
75 #else
76 #error tbb/machine/windows_api.h should only be used for Windows based platforms
77 #endif // _WIN32 || _WIN64
78 
79 #endif // __TBB_machine_windows_api_H