Make the file parsing threads run at lower priority

This commit is contained in:
Brad Davis 2016-02-08 23:40:36 -08:00
parent 07759bb5db
commit 421160eeb6
3 changed files with 19 additions and 0 deletions

View file

@ -47,6 +47,10 @@ AnimationReader::AnimationReader(const QUrl& url, const QByteArray& data) :
}
void AnimationReader::run() {
auto originalPriority = QThread::currentThread()->priority();
if (originalPriority == QThread::InheritPriority) {
originalPriority = QThread::NormalPriority;
}
try {
if (_data.isEmpty()) {
throw QString("Reply is NULL ?!");
@ -73,6 +77,7 @@ void AnimationReader::run() {
} catch (const QString& error) {
emit onError(299, error);
}
QThread::currentThread()->setPriority(originalPriority);
}
bool Animation::isLoaded() const {

View file

@ -50,6 +50,11 @@ GeometryReader::GeometryReader(const QUrl& url, const QByteArray& data, const QV
}
void GeometryReader::run() {
auto originalPriority = QThread::currentThread()->priority();
if (originalPriority == QThread::InheritPriority) {
originalPriority = QThread::NormalPriority;
}
QThread::currentThread()->setPriority(QThread::LowPriority);
try {
if (_data.isEmpty()) {
throw QString("Reply is NULL ?!");
@ -82,6 +87,8 @@ void GeometryReader::run() {
qCDebug(modelnetworking) << "Error reading " << _url << ": " << error;
emit onError(NetworkGeometry::ModelParseError, error);
}
QThread::currentThread()->setPriority(originalPriority);
}
NetworkGeometry::NetworkGeometry(const QUrl& url, bool delayLoad, const QVariantHash& mapping, const QUrl& textureBaseUrl) :

View file

@ -268,6 +268,12 @@ void ImageReader::listSupportedImageFormats() {
}
void ImageReader::run() {
auto originalPriority = QThread::currentThread()->priority();
if (originalPriority == QThread::InheritPriority) {
originalPriority = QThread::NormalPriority;
}
QThread::currentThread()->setPriority(QThread::LowPriority);
auto texture = _texture.toStrongRef();
if (!texture) {
qCWarning(modelnetworking) << "Could not get strong ref";
@ -306,6 +312,7 @@ void ImageReader::run() {
Q_ARG(const QImage&, image),
Q_ARG(void*, theTexture),
Q_ARG(int, originalWidth), Q_ARG(int, originalHeight));
QThread::currentThread()->setPriority(originalPriority);
}
void NetworkTexture::setImage(const QImage& image, void* voidTexture, int originalWidth,