1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-15 10:48:33 +01:00

Run the background library scanner at IDLE io priority on linux

This commit is contained in:
David Sansome 2010-03-21 15:55:58 +00:00
parent 530d58b4cf
commit 416670671f
2 changed files with 56 additions and 2 deletions

View File

@ -6,13 +6,42 @@
#include <boost/shared_ptr.hpp>
#ifdef Q_OS_LINUX
# include <sys/syscall.h>
#endif
class BackgroundThreadBase : public QThread {
Q_OBJECT
public:
BackgroundThreadBase(QObject* parent = 0) : QThread(parent) {}
BackgroundThreadBase(QObject* parent = 0) : QThread(parent), io_priority_(IOPRIO_CLASS_NONE) {}
virtual ~BackgroundThreadBase() {}
// Borrowed from schedutils
enum IoPriority {
IOPRIO_CLASS_NONE = 0,
IOPRIO_CLASS_RT,
IOPRIO_CLASS_BE,
IOPRIO_CLASS_IDLE,
};
void set_io_priority(IoPriority priority) { io_priority_ = priority; }
signals:
void Initialised();
protected:
// Borrowed from schedutils
static inline int ioprio_set(int which, int who, int ioprio);
static inline int gettid();
enum {
IOPRIO_WHO_PROCESS = 1,
IOPRIO_WHO_PGRP,
IOPRIO_WHO_USER,
};
static const int IOPRIO_CLASS_SHIFT = 13;
IoPriority io_priority_;
};
template <typename T>
@ -49,6 +78,13 @@ BackgroundThread<T>::~BackgroundThread() {
template <typename T>
void BackgroundThread<T>::run() {
#ifdef Q_OS_LINUX
if (io_priority_ != IOPRIO_CLASS_NONE) {
ioprio_set(IOPRIO_WHO_PROCESS, gettid(),
4 | io_priority_ << IOPRIO_CLASS_SHIFT);
}
#endif
worker_.reset(new T);
emit Initialised();
@ -57,4 +93,20 @@ void BackgroundThread<T>::run() {
worker_.reset();
}
int BackgroundThreadBase::ioprio_set(int which, int who, int ioprio) {
#ifdef Q_OS_LINUX
return syscall(SYS_ioprio_set, which, who, ioprio);
#else
return 0;
#endif
}
int BackgroundThreadBase::gettid() {
#ifdef Q_OS_LINUX
return syscall(SYS_gettid);
#else
return 0;
#endif
}
#endif // BACKGROUNDTHREAD_H

View File

@ -35,7 +35,9 @@ void Library::StartThreads() {
Q_ASSERT(waiting_for_threads_);
backend_->start();
watcher_->start();
watcher_->set_io_priority(BackgroundThreadBase::IOPRIO_CLASS_IDLE);
watcher_->start(QThread::IdlePriority);
}
void Library::BackendInitialised() {