Cleanup OS class
Remove unused HFTimer stuff (we have std::chrono instead) GetNumCores() returns uint32, and can be trusted more reliablymaster
parent
64e768e9c5
commit
04059e32a0
11
src/OS.h
11
src/OS.h
|
@ -7,8 +7,8 @@
|
||||||
* Operating system specific functionality, such as
|
* Operating system specific functionality, such as
|
||||||
* raising a message dialog
|
* raising a message dialog
|
||||||
*/
|
*/
|
||||||
#include "libs.h"
|
|
||||||
#include "utils.h"
|
#include <string>
|
||||||
|
|
||||||
namespace OS {
|
namespace OS {
|
||||||
|
|
||||||
|
@ -23,13 +23,8 @@ namespace OS {
|
||||||
void EnableFPE();
|
void EnableFPE();
|
||||||
void DisableFPE();
|
void DisableFPE();
|
||||||
|
|
||||||
// High frequency timer. HFTimer() returns count, HFTimerFreq() returns frequency.
|
|
||||||
// should not be considered reliable
|
|
||||||
Uint64 HFTimerFreq();
|
|
||||||
Uint64 HFTimer();
|
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine
|
// http://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine
|
||||||
int GetNumCores();
|
uint32_t GetNumCores();
|
||||||
|
|
||||||
// return a string describing the operating system that the game is running on, useful!
|
// return a string describing the operating system that the game is running on, useful!
|
||||||
const std::string GetOSInfoString();
|
const std::string GetOSInfoString();
|
||||||
|
|
|
@ -434,12 +434,11 @@ void Pi::Init(const std::map<std::string, std::string> &options, bool no_gui)
|
||||||
|
|
||||||
// get threads up
|
// get threads up
|
||||||
Uint32 numThreads = config->Int("WorkerThreads");
|
Uint32 numThreads = config->Int("WorkerThreads");
|
||||||
const int numCores = OS::GetNumCores();
|
numThreads = numThreads ? numThreads : std::max(OS::GetNumCores() - 1, 1U);
|
||||||
assert(numCores > 0);
|
Pi::asyncJobQueue.reset(new AsyncJobQueue(numThreads));
|
||||||
if (numThreads == 0) numThreads = std::max(Uint32(numCores) - 1, 1U);
|
Pi::syncJobQueue.reset(new SyncJobQueue);
|
||||||
asyncJobQueue.reset(new AsyncJobQueue(numThreads));
|
|
||||||
Output("started %d worker threads\n", numThreads);
|
Output("started %d worker threads\n", numThreads);
|
||||||
syncJobQueue.reset(new SyncJobQueue);
|
|
||||||
|
|
||||||
Output("ShipType::Init()\n");
|
Output("ShipType::Init()\n");
|
||||||
// XXX early, Lua init needs it
|
// XXX early, Lua init needs it
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "OS.h"
|
#include "OS.h"
|
||||||
#include "buildopts.h"
|
#include "buildopts.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <fenv.h>
|
#include <fenv.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
@ -64,19 +66,7 @@ namespace OS {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 HFTimerFreq()
|
uint32_t GetNumCores()
|
||||||
{
|
|
||||||
return 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint64 HFTimer()
|
|
||||||
{
|
|
||||||
timeval t;
|
|
||||||
gettimeofday(&t, 0);
|
|
||||||
return Uint64(t.tv_sec) * 1000000 + Uint64(t.tv_usec);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetNumCores()
|
|
||||||
{
|
{
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
int nm[2];
|
int nm[2];
|
||||||
|
@ -96,7 +86,11 @@ namespace OS {
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
#else
|
#else
|
||||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
// sysconf can return -1 if _SC_NPROCESSORS_ONLN is not supported
|
||||||
|
int count = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
// There's definitely at least one core.
|
||||||
|
// (What are you running Pioneer on otherwise, a potato battery?)
|
||||||
|
return count > 0 ? uint32_t(count) : 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,21 +115,7 @@ namespace OS {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint64 HFTimerFreq()
|
uint32_t GetNumCores()
|
||||||
{
|
|
||||||
LARGE_INTEGER i;
|
|
||||||
QueryPerformanceFrequency(&i);
|
|
||||||
return i.QuadPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint64 HFTimer()
|
|
||||||
{
|
|
||||||
LARGE_INTEGER i;
|
|
||||||
QueryPerformanceCounter(&i);
|
|
||||||
return i.QuadPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetNumCores()
|
|
||||||
{
|
{
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
|
|
Loading…
Reference in New Issue