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:
crs 2003-05-03 12:37:03 +00:00
parent 42ea6306f6
commit 8d9134f93a
3 changed files with 44 additions and 27 deletions

View File

@ -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 { else if (index > s_pMax) {
switch (n) { // highest priority
case 0: n = THREAD_PRIORITY_NORMAL; break; index = s_pMax;
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); SetPriorityClass(thread->m_thread, s_pClass[index].m_class);
SetThreadPriority(thread->m_thread, n); SetThreadPriority(thread->m_thread, s_pClass[index].m_level);
} }
void void

View File

@ -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 {

View File

@ -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 {