1
0
Fork 0
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:
reuk 2022-11-08 16:49:46 +00:00
parent 06a71ccce0
commit fbf4be05b2
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
2 changed files with 14 additions and 8 deletions

View file

@ -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;
}
//==============================================================================

View file

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