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:
parent
530d58b4cf
commit
416670671f
@ -6,13 +6,42 @@
|
|||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
# include <sys/syscall.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class BackgroundThreadBase : public QThread {
|
class BackgroundThreadBase : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
BackgroundThreadBase(QObject* parent = 0) : QThread(parent) {}
|
BackgroundThreadBase(QObject* parent = 0) : QThread(parent), io_priority_(IOPRIO_CLASS_NONE) {}
|
||||||
virtual ~BackgroundThreadBase() {}
|
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:
|
signals:
|
||||||
void Initialised();
|
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>
|
template <typename T>
|
||||||
@ -49,6 +78,13 @@ BackgroundThread<T>::~BackgroundThread() {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void BackgroundThread<T>::run() {
|
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);
|
worker_.reset(new T);
|
||||||
|
|
||||||
emit Initialised();
|
emit Initialised();
|
||||||
@ -57,4 +93,20 @@ void BackgroundThread<T>::run() {
|
|||||||
worker_.reset();
|
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
|
#endif // BACKGROUNDTHREAD_H
|
||||||
|
@ -35,7 +35,9 @@ void Library::StartThreads() {
|
|||||||
Q_ASSERT(waiting_for_threads_);
|
Q_ASSERT(waiting_for_threads_);
|
||||||
|
|
||||||
backend_->start();
|
backend_->start();
|
||||||
watcher_->start();
|
|
||||||
|
watcher_->set_io_priority(BackgroundThreadBase::IOPRIO_CLASS_IDLE);
|
||||||
|
watcher_->start(QThread::IdlePriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Library::BackendInitialised() {
|
void Library::BackendInitialised() {
|
||||||
|
Loading…
Reference in New Issue
Block a user