mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Android: Set thread priority using user-provided value
This commit is contained in:
parent
06a71ccce0
commit
fbf4be05b2
2 changed files with 14 additions and 8 deletions
|
|
@ -354,6 +354,13 @@ pthread_t juce_createRealtimeAudioThread (void* (*entry) (void*), void* userPtr)
|
|||
|
||||
extern JavaVM* androidJNIJavaVM;
|
||||
|
||||
static auto setPriorityOfThisThread (Thread::Priority p)
|
||||
{
|
||||
return setpriority (PRIO_PROCESS,
|
||||
(id_t) gettid(),
|
||||
ThreadPriorities::getNativePriority (p)) == 0;
|
||||
}
|
||||
|
||||
bool Thread::createNativeThread (Priority)
|
||||
{
|
||||
if (isRealtime())
|
||||
|
|
@ -372,6 +379,8 @@ bool Thread::createNativeThread (Priority)
|
|||
{
|
||||
auto* myself = static_cast<Thread*> (userData);
|
||||
|
||||
setPriorityOfThisThread (myself->priority);
|
||||
|
||||
juce_threadEntryPoint (myself);
|
||||
|
||||
if (androidJNIJavaVM != nullptr)
|
||||
|
|
@ -404,14 +413,15 @@ Thread::Priority Thread::getPriority() const
|
|||
return ThreadPriorities::getJucePriority (native);
|
||||
}
|
||||
|
||||
bool Thread::setPriority (Priority)
|
||||
bool Thread::setPriority (Priority priorityIn)
|
||||
{
|
||||
jassert (Thread::getCurrentThreadId() == getThreadId());
|
||||
|
||||
if (isRealtime())
|
||||
return false;
|
||||
|
||||
return setpriority (PRIO_PROCESS, (id_t) gettid(), ThreadPriorities::getNativePriority (priority)) == 0;
|
||||
const auto priorityToUse = priority = priorityIn;
|
||||
return setPriorityOfThisThread (priorityToUse) == 0;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -81,10 +81,6 @@ void Thread::threadEntryPoint()
|
|||
const CurrentThreadHolder::Ptr currentThreadHolder (getCurrentThreadHolder());
|
||||
currentThreadHolder->value = this;
|
||||
|
||||
#if JUCE_ANDROID
|
||||
setPriority (priority);
|
||||
#endif
|
||||
|
||||
if (threadName.isNotEmpty())
|
||||
setCurrentThreadName (threadName);
|
||||
|
||||
|
|
@ -130,10 +126,10 @@ bool Thread::startThreadInternal (Priority threadPriority)
|
|||
shouldExit = false;
|
||||
|
||||
// 'priority' is essentially useless on Linux as only realtime
|
||||
// has any options but we need to set this here to satsify
|
||||
// has any options but we need to set this here to satisfy
|
||||
// later queries, otherwise we get inconsistent results across
|
||||
// platforms.
|
||||
#if JUCE_LINUX || JUCE_BSD
|
||||
#if JUCE_ANDROID || JUCE_LINUX || JUCE_BSD
|
||||
priority = threadPriority;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue