mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 19:54:19 +01:00
[util] Implement thread set_priority on non-Windows platforms
This commit is contained in:
parent
97350d6c35
commit
1c1dba4624
@ -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, ¶m);
|
||||
}
|
||||
};
|
||||
|
||||
using mutex = std::mutex;
|
||||
using thread = std::thread;
|
||||
using recursive_mutex = std::recursive_mutex;
|
||||
using condition_variable = std::condition_variable;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user