issue#11: cds: changed __CDS_ guard prefix to CDSLIB_ for all .h files
[libcds.git] / cds / os / aix / topology.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_OS_AIX_TOPOLOGY_H
4 #define CDSLIB_OS_AIX_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/os/details/fake_topology.h>
11
12 #include <unistd.h>
13
14 #ifdef _AIX53
15 #   include <sys/processor.h>
16 #endif
17
18 namespace cds { namespace OS {
19
20     ///  IBM AIX specific wrappers
21     CDS_CXX11_INLINE_NAMESPACE namespace Aix {
22
23         /// System topology
24         /**
25             The implementation assumes that the processor IDs are in numerical order
26             from 0 to N - 1, where N - count of processor in the system
27         */
28         struct topology: public OS::details::fake_topology
29         {
30         private:
31             //@cond
32             typedef OS::details::fake_topology  base_class;
33             //@endcond
34         public:
35             /// Logical processor count for the system
36             static unsigned int processor_count()
37             {
38                 long nCount = ::sysconf(_SC_NPROCESSORS_ONLN);
39                 if ( nCount == -1 )
40                     return  1;
41                 return (unsigned int) nCount;
42             }
43
44             /// Get current processor number
45             /**
46                 Caveat: AIX has no "get current processor number" system call.
47                 The function emulates "current processor number" using thread-specific data.
48             */
49             static unsigned int current_processor()
50             {
51 #           if defined(_AIX53) && _AIX53 == 1
52                 // AIX 5.3 has undocumented function mycpu() in sys/processor.h
53                 return ::mycpu();
54 #           else
55                 return base_class::current_processor();
56 #           endif
57             }
58
59             /// Synonym for \ref current_processor
60             static unsigned int native_current_processor()
61             {
62                 return current_processor();
63             }
64
65             //@cond
66             static void init()
67             {}
68             static void fini()
69             {}
70             //@endcond
71         };
72     }   // namespace Aix
73
74 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
75     using Aix::topology;
76 #endif
77 }}  // namespace cds::OS
78
79 #endif  // #ifndef CDSLIB_OS_AIX_TOPOLOGY_H