Oolite 1.91.0.7745-260117-205bce7
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 105 of file OOCPUInfo.m.

106{
107 if (!sInited) OOCPUInfoInit();
108 return (sNumberOfCPUs != 0) ? sNumberOfCPUs : 1;
109}
void OOCPUInfoInit(void)
Definition OOCPUInfo.m:64
static NSUInteger sNumberOfCPUs
Definition OOCPUInfo.m:61
static BOOL sInited

References OOCPUInfoInit(), sInited, and sNumberOfCPUs.

Here is the call graph for this function:

◆ OOCPUInfoInit()

void OOCPUInfoInit ( void )

Definition at line 64 of file OOCPUInfo.m.

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

References OOLog, sInited, and sNumberOfCPUs.

Referenced by Universe::initWithGameView:, and OOCPUCount().

Here is the caller graph for this function:

Variable Documentation

◆ sInited

BOOL sInited = NO
static

Definition at line 58 of file OOCPUInfo.m.

◆ sNumberOfCPUs

NSUInteger sNumberOfCPUs = 0
static

Definition at line 61 of file OOCPUInfo.m.

Referenced by OOCPUCount(), and OOCPUInfoInit().