Merge pull request #3025 from talentraspel/19753

replaced usleep for windows
This commit is contained in:
Brad Hefta-Gaub 2014-06-16 17:40:01 -07:00
commit 5b62733a36
3 changed files with 52 additions and 9 deletions

View file

@ -1419,7 +1419,7 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo)
// proportional to the accelerator ratio.
#ifdef Q_OS_WIN
const float Audio::CALLBACK_ACCELERATOR_RATIO = 0.4f;
const float Audio::CALLBACK_ACCELERATOR_RATIO = 0.1f;
#endif
#ifdef Q_OS_MAC

View file

@ -21,6 +21,8 @@
#include <SharedUtil.h>
#include <QThread>
#include "InterfaceConfig.h"
#include "ui/TextRenderer.h"
#include "VoxelConstants.h"
@ -409,8 +411,44 @@ void runTimingTests() {
float NSEC_TO_USEC = 1.0f / 1000.0f;
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("QElapsedTimer::nsecElapsed() usecs: %f", elapsedUsecs / (float) numTests);
qDebug("QElapsedTimer::nsecElapsed() usecs: %f", elapsedUsecs);
// Test sleep functions for accuracy
startTime.start();
QThread::msleep(1);
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("QThread::msleep(1) ms: %f", elapsedUsecs / 1000.0f);
startTime.start();
QThread::sleep(1);
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("QThread::sleep(1) ms: %f", elapsedUsecs / 1000.0f);
startTime.start();
usleep(1);
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("usleep(1) ms: %f", elapsedUsecs / 1000.0f);
startTime.start();
usleep(10);
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("usleep(10) ms: %f", elapsedUsecs / 1000.0f);
startTime.start();
usleep(100);
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("usleep(100) ms: %f", elapsedUsecs / 1000.0f);
startTime.start();
usleep(1000);
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("usleep(1000) ms: %f", elapsedUsecs / 1000.0f);
startTime.start();
usleep(15000);
elapsedUsecs = (float)startTime.nsecsElapsed() * NSEC_TO_USEC;
qDebug("usleep(15000) ms: %f", elapsedUsecs / 1000.0f);
// Random number generation
startTime.start();
for (int i = 0; i < numTests; i++) {

View file

@ -26,6 +26,7 @@
#include <QtCore/QDebug>
#include <QDateTime>
#include <QElapsedTimer>
#include <QThread>
#include "OctalCode.h"
#include "SharedUtil.h"
@ -415,13 +416,17 @@ void printVoxelCode(unsigned char* voxelCode) {
#ifdef _WIN32
void usleep(int waitTime) {
__int64 time1 = 0, time2 = 0, sysFreq = 0;
QueryPerformanceCounter((LARGE_INTEGER *)&time1);
QueryPerformanceFrequency((LARGE_INTEGER *)&sysFreq);
do {
QueryPerformanceCounter((LARGE_INTEGER *)&time2);
} while( (time2 - time1) < waitTime);
const quint64 BUSY_LOOP_USECS = 2000;
quint64 compTime = waitTime + usecTimestampNow();
quint64 compTimeSleep = compTime - BUSY_LOOP_USECS;
while (true) {
if (usecTimestampNow() < compTimeSleep) {
QThread::msleep(1);
}
if (usecTimestampNow() >= compTime) {
break;
}
}
}
#endif