Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOCPUInfo.m File Reference
import "OOCPUInfo.h"
#include <stdlib.h>
#include <sys/sysctl.h>
+ Include dependency graph for OOCPUInfo.m:

Go to the source code of this file.

Functions

void OOCPUInfoInit (void)
 
NSUInteger OOCPUCount (void)
 

Variables

static BOOL sInited = NO
 
static NSUInteger sNumberOfCPUs = 0
 

Function Documentation

◆ OOCPUCount()

NSUInteger OOCPUCount ( void )

Definition at line 101 of file OOCPUInfo.m.

102{
103 if (!sInited) OOCPUInfoInit();
104 return (sNumberOfCPUs != 0) ? sNumberOfCPUs : 1;
105}
void OOCPUInfoInit(void)
Definition OOCPUInfo.m:60
static BOOL sInited
Definition OOCPUInfo.m:54
static NSUInteger sNumberOfCPUs
Definition OOCPUInfo.m:57

References OOCPUInfoInit(), sInited, and sNumberOfCPUs.

+ Here is the call graph for this function:

◆ OOCPUInfoInit()

void OOCPUInfoInit ( void )

Definition at line 60 of file OOCPUInfo.m.

61{
62 if (sInited) return;
63
64 // Verify correctness of endian macros
65 uint8_t endianTag[4] = {0x12, 0x34, 0x56, 0x78};
66
67#if OOLITE_BIG_ENDIAN
68 if (*(uint32_t*)endianTag != 0x12345678)
69 {
70 OOLog(@"cpuInfo.endianTest.failed", @"%@", @"OOLITE_BIG_ENDIAN is set, but the system is not big-endian -- aborting.");
71 exit(EXIT_FAILURE);
72 }
73#endif
74
75#if OOLITE_LITTLE_ENDIAN
76 if (*(uint32_t*)endianTag != 0x78563412)
77 {
78 OOLog(@"cpuInfo.endianTest.failed", @"%@", @"OOLITE_LITTLE_ENDIAN is set, but the system is not little-endian -- aborting.");
79 exit(EXIT_FAILURE);
80 }
81#endif
82
83 // Count processors
84#if OOLITE_MAC_OS_X
85 sNumberOfCPUs = [[NSProcessInfo processInfo] processorCount];
86#elif OOLITE_WINDOWS
87 SYSTEM_INFO sysInfo;
88
89 GetSystemInfo(&sysInfo);
90 sNumberOfCPUs = sysInfo.dwNumberOfProcessors;
91#elif defined _SC_NPROCESSORS_ONLN
92 sNumberOfCPUs = sysconf(_SC_NPROCESSORS_ONLN);
93#else
94 #warning Do not know how to find number of CPUs on this architecture.
95#endif // OS selection
96
97 sInited = YES;
98}
#define OOLog(class, format,...)
Definition OOLogging.h:88

References OOLog, sInited, and sNumberOfCPUs.

Referenced by OOCPUCount().

+ Here is the caller graph for this function:

Variable Documentation

◆ sInited

BOOL sInited = NO
static

Definition at line 54 of file OOCPUInfo.m.

Referenced by OOCPUCount(), and OOCPUInfoInit().

◆ sNumberOfCPUs

NSUInteger sNumberOfCPUs = 0
static

Definition at line 57 of file OOCPUInfo.m.

Referenced by OOCPUCount(), and OOCPUInfoInit().