[util] Implement thread set_priority on non-Windows platforms

This commit is contained in:
Joshua Ashton 2022-08-21 21:17:33 +01:00 committed by GitHub
parent 97350d6c35
commit 1c1dba4624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 8 deletions

View File

@ -15,18 +15,15 @@
namespace dxvk {
#ifdef _WIN32
/**
* \brief Thread priority
*/
enum class ThreadPriority : int32_t {
Lowest = THREAD_PRIORITY_LOWEST,
Low = THREAD_PRIORITY_BELOW_NORMAL,
Normal = THREAD_PRIORITY_NORMAL,
High = THREAD_PRIORITY_ABOVE_NORMAL,
Highest = THREAD_PRIORITY_HIGHEST,
Normal,
Lowest,
};
#ifdef _WIN32
/**
* \brief Thread helper class
*
@ -74,7 +71,13 @@ namespace dxvk {
}
void set_priority(ThreadPriority priority) {
::SetThreadPriority(m_handle, int32_t(priority));
int32_t value;
switch (priority) {
default:
case ThreadPriority::Normal: value = THREAD_PRIORITY_NORMAL; break;
case ThreadPriority::Lowest: value = THREAD_PRIORITY_LOWEST; break;
}
::SetThreadPriority(m_handle, int32_t(value));
}
private:
@ -332,8 +335,23 @@ namespace dxvk {
};
#else
class thread : public std::thread {
public:
using std::thread::thread;
void set_priority(ThreadPriority priority) {
::sched_param param = {};
int32_t policy;
switch (priority) {
default:
case ThreadPriority::Normal: policy = SCHED_OTHER; break;
case ThreadPriority::Lowest: policy = SCHED_IDLE; break;
}
::pthread_setschedparam(this->native_handle(), policy, &param);
}
};
using mutex = std::mutex;
using thread = std::thread;
using recursive_mutex = std::recursive_mutex;
using condition_variable = std::condition_variable;