Fix compilation error on 32 bit Windows
[blender.git] / intern / cycles / util / util_windows.cpp
1 /*
2  * Copyright 2011-2016 Blender Foundation
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 #include "util_windows.h"
18
19 #ifdef _WIN32
20
21 CCL_NAMESPACE_BEGIN
22
23 #ifdef _M_X64
24 #  include <VersionHelpers.h>
25 #endif
26
27 #if _WIN32_WINNT < 0x0601
28 tGetActiveProcessorGroupCount *GetActiveProcessorGroupCount;
29 tGetActiveProcessorCount *GetActiveProcessorCount;
30 tSetThreadGroupAffinity *SetThreadGroupAffinity;
31 #endif
32
33 static WORD GetActiveProcessorGroupCount_stub()
34 {
35         return 1;
36 }
37
38 static DWORD GetActiveProcessorCount_stub(WORD /*GroupNumber*/)
39 {
40         SYSTEM_INFO info;
41         GetSystemInfo(&info);
42         return info.dwNumberOfProcessors;
43 }
44
45 static BOOL SetThreadGroupAffinity_stub(
46         HANDLE /*hThread*/,
47         const GROUP_AFFINITY  * /*GroupAffinity*/,
48         PGROUP_AFFINITY /*PreviousGroupAffinity*/)
49 {
50         return TRUE;
51 }
52
53 static bool supports_numa()
54 {
55 #ifndef _M_X64
56         return false;
57 #else
58         return IsWindows7OrGreater();
59 #endif
60 }
61
62 void util_windows_init_numa_groups()
63 {
64         static bool initialized = false;
65         if(initialized) {
66                 return;
67         }
68         initialized = true;
69 #if _WIN32_WINNT < 0x0601
70         if(!supports_numa()) {
71                 /* Use stubs on platforms which doesn't have rean NUMA/Groups. */
72                 GetActiveProcessorGroupCount = GetActiveProcessorGroupCount_stub;
73                 GetActiveProcessorCount = GetActiveProcessorCount_stub;
74                 SetThreadGroupAffinity = SetThreadGroupAffinity_stub;
75                 return;
76         }
77         HMODULE kernel = GetModuleHandleA("kernel32.dll");
78 #  define READ_SYMBOL(sym) sym = (t##sym*)GetProcAddress(kernel, #sym)
79         READ_SYMBOL(GetActiveProcessorGroupCount);
80         READ_SYMBOL(GetActiveProcessorCount);
81         READ_SYMBOL(SetThreadGroupAffinity);
82 #  undef READ_SUMBOL
83 #endif
84 }
85
86 CCL_NAMESPACE_END
87
88 #endif  /* _WIN32 */