issue#11: cds: changed __CDS_ guard prefix to CDSLIB_ for all .h files
[libcds.git] / cds / os / sunos / topology.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_OS_SUNOS_TOPOLOGY_H
4 #define CDSLIB_OS_SUNOS_TOPOLOGY_H
5
6 #ifndef CDSLIB_OS_TOPOLOGY_H
7 #   error "<cds/os/topology.h> must be included instead"
8 #endif
9
10 #include <sys/processor.h>
11 #include <unistd.h>
12
13 namespace cds { namespace OS {
14
15     /// Sun Solaris-specific wrappers
16     CDS_CXX11_INLINE_NAMESPACE namespace Sun {
17
18         /// System topology
19         /**
20             The implementation assumes that the processor IDs are in numerical order
21             from 0 to N - 1, where N - count of processor in the system
22         */
23         struct topology {
24             /// Logical processor count for the system
25             static unsigned int processor_count()
26             {
27                 // Maybe, _SC_NPROCESSORS_ONLN? But _SC_NPROCESSORS_ONLN may change dynamically...
28                 long nCount = ::sysconf(_SC_NPROCESSORS_CONF);
29                 if ( nCount == -1 )
30                     return  1;
31                 return (unsigned int) nCount;
32             }
33
34             /// Get current processor number
35             static unsigned int current_processor()
36             {
37                 return  ::getcpuid();
38             }
39
40             /// Synonym for \ref current_processor
41             static unsigned int native_current_processor()
42             {
43                 return current_processor();
44             }
45
46             //@cond
47             static void init()
48             {}
49             static void fini()
50             {}
51             //@endcond
52         };
53     }   // namespace Sun
54
55 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
56     using Sun::topology;
57 #endif
58 }}  // namespace cds::OS
59
60 #endif  // #ifndef CDSLIB_OS_SUNOS_TOPOLOGY_H