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