3 #ifndef CDSLIB_OS_FREE_BSD_TOPOLOGY_H
4 #define CDSLIB_OS_FREE_BSD_TOPOLOGY_H
6 #ifndef CDSLIB_OS_TOPOLOGY_H
7 # error "<cds/os/topology.h> must be included instead"
10 #include <cds/os/details/fake_topology.h>
12 #include <sys/types.h>
13 #include <sys/sysctl.h>
15 namespace cds { namespace OS {
17 /// FreeBSD-specific wrappers
18 CDS_CXX11_INLINE_NAMESPACE namespace Free_BSD {
22 The implementation assumes that processor IDs are in numerical order
23 from 0 to N - 1, where N - count of processor in the system
25 struct topology: public OS::details::fake_topology
29 typedef OS::details::fake_topology base_class;
33 /// Logical processor count for the system
34 static unsigned int processor_count()
38 /* set the mib for hw.ncpu */
42 size_t len = sizeof(nCPU);
44 /* get the number of CPUs from the system */
45 return ::sysctl( mib, 2, &nCPU, &len, nullptr, 0 ) == 0 && nCPU > 0 ? (unsigned int)nCPU : 1;
48 /// Get current processor number
50 Caveat: FreeBSD has no "get current processor number" system call.
51 The function emulates "current processor number" using thread-specific data.
53 static unsigned int current_processor()
55 return base_class::current_processor();
58 /// Synonym for \ref current_processor
59 static unsigned int native_current_processor()
61 return current_processor();
71 } // namespace Free_BSD
73 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
74 using Free_BSD::topology;
76 }} // namespace cds::OS
78 #endif // #ifndef CDSLIB_OS_FREE_BSD_TOPOLOGY_H