mirror of
https://github.com/debauchee/barrier.git
synced 2024-12-25 20:13:23 +03:00
Boosted priority of main synergy threads to be very high (highest
realtime priority). After some testing it appears that anything less than this can starve synergy in some circumstances, preventing it from forwarding messages to clients. This is a rather risky change since synergy can now virtually take over a system if it behaves badly. This change only affects windows systems since lib/arch of other platforms don't yet attempt to boost priority.
This commit is contained in:
parent
42ea6306f6
commit
8d9134f93a
@ -348,35 +348,52 @@ CArchMultithreadWindows::cancelThread(CArchThread thread)
|
|||||||
void
|
void
|
||||||
CArchMultithreadWindows::setPriorityOfThread(CArchThread thread, int n)
|
CArchMultithreadWindows::setPriorityOfThread(CArchThread thread, int n)
|
||||||
{
|
{
|
||||||
|
struct CPriorityInfo {
|
||||||
|
public:
|
||||||
|
DWORD m_class;
|
||||||
|
int m_level;
|
||||||
|
};
|
||||||
|
static const CPriorityInfo s_pClass[] = {
|
||||||
|
{ IDLE_PRIORITY_CLASS, THREAD_PRIORITY_IDLE },
|
||||||
|
{ IDLE_PRIORITY_CLASS, THREAD_PRIORITY_LOWEST },
|
||||||
|
{ IDLE_PRIORITY_CLASS, THREAD_PRIORITY_BELOW_NORMAL },
|
||||||
|
{ IDLE_PRIORITY_CLASS, THREAD_PRIORITY_NORMAL },
|
||||||
|
{ IDLE_PRIORITY_CLASS, THREAD_PRIORITY_ABOVE_NORMAL },
|
||||||
|
{ IDLE_PRIORITY_CLASS, THREAD_PRIORITY_HIGHEST },
|
||||||
|
{ NORMAL_PRIORITY_CLASS, THREAD_PRIORITY_LOWEST },
|
||||||
|
{ NORMAL_PRIORITY_CLASS, THREAD_PRIORITY_BELOW_NORMAL },
|
||||||
|
{ NORMAL_PRIORITY_CLASS, THREAD_PRIORITY_NORMAL },
|
||||||
|
{ NORMAL_PRIORITY_CLASS, THREAD_PRIORITY_ABOVE_NORMAL },
|
||||||
|
{ NORMAL_PRIORITY_CLASS, THREAD_PRIORITY_HIGHEST },
|
||||||
|
{ HIGH_PRIORITY_CLASS, THREAD_PRIORITY_LOWEST },
|
||||||
|
{ HIGH_PRIORITY_CLASS, THREAD_PRIORITY_BELOW_NORMAL },
|
||||||
|
{ HIGH_PRIORITY_CLASS, THREAD_PRIORITY_NORMAL },
|
||||||
|
{ HIGH_PRIORITY_CLASS, THREAD_PRIORITY_ABOVE_NORMAL },
|
||||||
|
{ HIGH_PRIORITY_CLASS, THREAD_PRIORITY_HIGHEST },
|
||||||
|
{ REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_IDLE },
|
||||||
|
{ REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_LOWEST },
|
||||||
|
{ REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_BELOW_NORMAL },
|
||||||
|
{ REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_NORMAL },
|
||||||
|
{ REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_ABOVE_NORMAL },
|
||||||
|
{ REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_HIGHEST },
|
||||||
|
{ REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL}
|
||||||
|
};
|
||||||
|
static const size_t s_pMax = sizeof(s_pClass) / sizeof(s_pClass[0]) - 1;
|
||||||
|
static const size_t s_pBase = 8; // index of normal priority
|
||||||
|
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
|
|
||||||
DWORD pClass = NORMAL_PRIORITY_CLASS;
|
size_t index = s_pBase - n;
|
||||||
if (n < 0) {
|
if (index < 0) {
|
||||||
switch (-n) {
|
// lowest priority
|
||||||
case 1: n = THREAD_PRIORITY_ABOVE_NORMAL; break;
|
index = 0;
|
||||||
case 2: n = THREAD_PRIORITY_HIGHEST; break;
|
|
||||||
default:
|
|
||||||
pClass = HIGH_PRIORITY_CLASS;
|
|
||||||
switch (-n - 3) {
|
|
||||||
case 0: n = THREAD_PRIORITY_LOWEST; break;
|
|
||||||
case 1: n = THREAD_PRIORITY_BELOW_NORMAL; break;
|
|
||||||
case 2: n = THREAD_PRIORITY_NORMAL; break;
|
|
||||||
case 3: n = THREAD_PRIORITY_ABOVE_NORMAL; break;
|
|
||||||
default: n = THREAD_PRIORITY_HIGHEST; break;
|
|
||||||
}
|
}
|
||||||
break;
|
else if (index > s_pMax) {
|
||||||
|
// highest priority
|
||||||
|
index = s_pMax;
|
||||||
}
|
}
|
||||||
}
|
SetPriorityClass(thread->m_thread, s_pClass[index].m_class);
|
||||||
else {
|
SetThreadPriority(thread->m_thread, s_pClass[index].m_level);
|
||||||
switch (n) {
|
|
||||||
case 0: n = THREAD_PRIORITY_NORMAL; break;
|
|
||||||
case 1: n = THREAD_PRIORITY_BELOW_NORMAL; break;
|
|
||||||
case 2: n = THREAD_PRIORITY_LOWEST; break;
|
|
||||||
default: n = THREAD_PRIORITY_IDLE; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SetPriorityClass(thread->m_thread, pClass);
|
|
||||||
SetThreadPriority(thread->m_thread, n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -40,7 +40,7 @@ void
|
|||||||
CPrimaryScreen::mainLoop()
|
CPrimaryScreen::mainLoop()
|
||||||
{
|
{
|
||||||
// change our priority
|
// change our priority
|
||||||
CThread::getCurrentThread().setPriority(-3);
|
CThread::getCurrentThread().setPriority(-13);
|
||||||
|
|
||||||
// run event loop
|
// run event loop
|
||||||
try {
|
try {
|
||||||
|
@ -38,7 +38,7 @@ void
|
|||||||
CSecondaryScreen::mainLoop()
|
CSecondaryScreen::mainLoop()
|
||||||
{
|
{
|
||||||
// change our priority
|
// change our priority
|
||||||
CThread::getCurrentThread().setPriority(-7);
|
CThread::getCurrentThread().setPriority(-13);
|
||||||
|
|
||||||
// run event loop
|
// run event loop
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user