CpuUsage: optimise performance further

This commit is contained in:
李通洲
2022-11-25 23:14:41 +08:00
parent c6a9217c74
commit 4316ba988b
+4 -11
View File
@@ -8,29 +8,22 @@
// We need to use uint64_t because sizeof(long) == 4 on Windows
const char* ffGetCpuUsageInfo(uint64_t* inUseAll, uint64_t* totalAll);
static uint64_t inUseAll1, totalAll1, startTime;
static uint64_t inUseAll1, totalAll1;
void ffPrepareCPUUsage()
{
startTime = ffTimeGetTick();
ffGetCpuUsageInfo(&inUseAll1, &totalAll1);
}
const char* ffGetCpuUsageResult(double* result)
{
const char* error = NULL;
if(startTime == 0)
if(inUseAll1 == 0 && totalAll1 == 0)
{
error = ffGetCpuUsageInfo(&inUseAll1, &totalAll1);
if(error)
return error;
ffTimeSleep(250);
}
else
{
uint64_t duration = ffTimeGetTick() - startTime;
if(duration < 250)
ffTimeSleep(250 - (uint32_t) duration);
ffTimeSleep(200);
}
while(true)
@@ -46,6 +39,6 @@ const char* ffGetCpuUsageResult(double* result)
return NULL;
}
else
ffTimeSleep(250);
ffTimeSleep(200);
}
}