Fixed min/max macro problem in MS VC++
[libcds.git] / cds / os / win / topology.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_OS_WIN_TOPOLOGY_H
4 #define CDSLIB_OS_WIN_TOPOLOGY_H
5
6 #ifndef CDSLIB_OS_TOPOLOGY_H
7 #   error "<cds/os/topology.h> must be included instead"
8 #endif
9
10 #include <cds/details/defs.h>
11 #define NOMINMAX
12 #include <windows.h>
13
14 namespace cds { namespace OS {
15
16     /// Windows-specific wrappers
17     CDS_CXX11_INLINE_NAMESPACE namespace Win32 {
18
19         /// System topology
20         /**
21             The implementation assumes that:
22                 \li the system has no more than 64 logical processors;
23                 \li processor IDs are in numerical order from 0 to N - 1, where N - count of processor in the system
24         */
25         struct CDS_EXPORT_API topology
26         {
27 #   if _WIN32_WINNT >= 0x0601       // >= Windows 7
28             static unsigned int    processor_count()
29             {
30                 return ::GetActiveProcessorCount( ALL_PROCESSOR_GROUPS );
31             }
32 #   else    // < Windows 7
33             /// Logical processor count for the system
34             static unsigned int processor_count();
35 #   endif
36
37 #   if _WIN32_WINNT >= 0x0600   // >= Windows Vista
38             static unsigned int current_processor()
39             {
40                 return ::GetCurrentProcessorNumber();
41             }
42 #   else    // < Windows Vista
43             /// Get current processor number
44             static unsigned int current_processor();
45 #   endif
46
47             /// Synonym for \ref current_processor
48             static unsigned int native_current_processor()
49             {
50                 return current_processor();
51             }
52
53             //@cond
54             static void init()
55             {}
56             static void fini()
57             {}
58             //@endcond
59         };
60
61     }   // namespace Win32
62
63 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
64     using Win32::topology;
65 #endif
66 }}  // namespace cds::OS
67
68
69
70 #endif  // #ifndef CDSLIB_OS_WIN_TOPOLOGY_H