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
|
||||
* raising a message dialog
|
||||
*/
|
||||
#include "libs.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OS {
|
||||
|
||||
|
@ -23,13 +23,8 @@ namespace OS {
|
|||
void EnableFPE();
|
||||
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
|
||||
int GetNumCores();
|
||||
uint32_t GetNumCores();
|
||||
|
||||
// return a string describing the operating system that the game is running on, useful!
|
||||
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
|
||||
Uint32 numThreads = config->Int("WorkerThreads");
|
||||
const int numCores = OS::GetNumCores();
|
||||
assert(numCores > 0);
|
||||
if (numThreads == 0) numThreads = std::max(Uint32(numCores) - 1, 1U);
|
||||
asyncJobQueue.reset(new AsyncJobQueue(numThreads));
|
||||
numThreads = numThreads ? numThreads : std::max(OS::GetNumCores() - 1, 1U);
|
||||
Pi::asyncJobQueue.reset(new AsyncJobQueue(numThreads));
|
||||
Pi::syncJobQueue.reset(new SyncJobQueue);
|
||||
|
||||
Output("started %d worker threads\n", numThreads);
|
||||
syncJobQueue.reset(new SyncJobQueue);
|
||||
|
||||
Output("ShipType::Init()\n");
|
||||
// XXX early, Lua init needs it
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "FileSystem.h"
|
||||
#include "OS.h"
|
||||
#include "buildopts.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <fenv.h>
|
||||
#include <sys/time.h>
|
||||
|
@ -64,19 +66,7 @@ namespace OS {
|
|||
#endif
|
||||
}
|
||||
|
||||
Uint64 HFTimerFreq()
|
||||
{
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
Uint64 HFTimer()
|
||||
{
|
||||
timeval t;
|
||||
gettimeofday(&t, 0);
|
||||
return Uint64(t.tv_sec) * 1000000 + Uint64(t.tv_usec);
|
||||
}
|
||||
|
||||
int GetNumCores()
|
||||
uint32_t GetNumCores()
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
int nm[2];
|
||||
|
@ -96,7 +86,11 @@ namespace OS {
|
|||
}
|
||||
return count;
|
||||
#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
|
||||
}
|
||||
|
||||
|
|
|
@ -115,21 +115,7 @@ namespace OS {
|
|||
#endif
|
||||
}
|
||||
|
||||
Uint64 HFTimerFreq()
|
||||
{
|
||||
LARGE_INTEGER i;
|
||||
QueryPerformanceFrequency(&i);
|
||||
return i.QuadPart;
|
||||
}
|
||||
|
||||
Uint64 HFTimer()
|
||||
{
|
||||
LARGE_INTEGER i;
|
||||
QueryPerformanceCounter(&i);
|
||||
return i.QuadPart;
|
||||
}
|
||||
|
||||
int GetNumCores()
|
||||
uint32_t GetNumCores()
|
||||
{
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
|
|
Loading…
Reference in New Issue