1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

Minor code clean-ups.

This commit is contained in:
Julian Storer 2010-05-08 18:16:09 +01:00
parent 87e416a278
commit 266494a1b9
41 changed files with 1383 additions and 1427 deletions

View file

@ -37,9 +37,6 @@ void JUCE_API juce_threadEntryPoint (void*);
void* threadEntryProc (void* value)
{
// New threads start off as root when running suid
Process::lowerPrivilege();
juce_threadEntryPoint (value);
return 0;
}
@ -60,7 +57,7 @@ void* juce_createThread (void* userData)
void juce_killThread (void* handle)
{
if (handle != 0)
pthread_cancel ((pthread_t)handle);
pthread_cancel ((pthread_t) handle);
}
void juce_setCurrentThreadName (const String& /*name*/)
@ -72,26 +69,25 @@ Thread::ThreadID Thread::getCurrentThreadId()
return (ThreadID) pthread_self();
}
/*
* This is all a bit non-ideal... the trouble is that on Linux you
* need to call setpriority to affect the dynamic priority for
* non-realtime processes, but this requires the pid, which is not
* accessible from the pthread_t. We could get it by calling getpid
* once each thread has started, but then we would need a list of
* running threads etc etc.
* Also there is no such thing as IDLE priority on Linux.
* For the moment, map idle, low and normal process priorities to
* SCHED_OTHER, with the thread priority ignored for these classes.
* Map high priority processes to the lower half of the SCHED_RR
* range, and realtime to the upper half
*/
/* This is all a bit non-ideal... the trouble is that on Linux you
need to call setpriority to affect the dynamic priority for
non-realtime processes, but this requires the pid, which is not
accessible from the pthread_t. We could get it by calling getpid
once each thread has started, but then we would need a list of
running threads etc etc.
Also there is no such thing as IDLE priority on Linux.
For the moment, map idle, low and normal process priorities to
SCHED_OTHER, with the thread priority ignored for these classes.
Map high priority processes to the lower half of the SCHED_RR
range, and realtime to the upper half.
// priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
// priority of the current thread
priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
priority of the current thread
*/
bool juce_setThreadPriority (void* handle, int priority)
{
struct sched_param param;
int policy, maxp, minp, pri;
int policy;
if (handle == 0)
handle = (void*) pthread_self();
@ -99,20 +95,17 @@ bool juce_setThreadPriority (void* handle, int priority)
if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
&& policy != SCHED_OTHER)
{
minp = sched_get_priority_min(policy);
maxp = sched_get_priority_max(policy);
int minp = sched_get_priority_min (policy);
int maxp = sched_get_priority_max (policy);
pri = ((maxp - minp) / 2) * (priority - 1) / 9;
int pri = ((maxp - minp) / 2) * (priority - 1) / 9;
if (param.__sched_priority >= (minp + (maxp - minp) / 2))
// Realtime process priority
param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
param.__sched_priority = minp + ((maxp - minp) / 2) + pri; // (realtime)
else
// High process priority
param.__sched_priority = minp + pri;
param.__sched_priority = minp + pri; // (high)
param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
}