From eff63546e002be1801effd3e3557a52dca8e6314 Mon Sep 17 00:00:00 2001 From: chucknology Date: Thu, 20 Jun 2024 18:28:40 -0700 Subject: [PATCH 1/2] Fix Android thread priority Android threads are Linux threads which differ from the POSIX standard. Calling pthread_setschedparam does not produce the intended effect on Android. --- src/sfizz/FilePool.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index fa7e5afb3..5157ba0ef 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -42,6 +42,8 @@ #include #if defined(_WIN32) #include +#elif defined(__ANDROID__) +#include #else #include #endif @@ -609,6 +611,13 @@ void sfz::FilePool::raiseCurrentThreadPriority() noexcept std::system_error error(GetLastError(), std::system_category()); DBG("[sfizz] Cannot set current thread priority: " << error.what()); } +#elif defined(__ANDROID__) + int tid = gettid(); // Android specific function to get thread ID + int priority = -20; // Highest priority for nice value + if (setpriority(PRIO_PROCESS, tid, priority) != 0) { + // setpriority sets errno on failure + DBG("[sfizz] Cannot set current thread priority: " << strerror(errno)); + } #else pthread_t thread = pthread_self(); int policy; From 8c5ccc25c83a818aa8a3e7f0ca95d1b5b8048af0 Mon Sep 17 00:00:00 2001 From: chucknology Date: Sun, 15 Jun 2025 07:07:13 -0700 Subject: [PATCH 2/2] Change FilePool Android thread priority to -2 (FOREGROUND) --- src/sfizz/FilePool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index 5157ba0ef..bab9fbd05 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -612,8 +612,8 @@ void sfz::FilePool::raiseCurrentThreadPriority() noexcept DBG("[sfizz] Cannot set current thread priority: " << error.what()); } #elif defined(__ANDROID__) - int tid = gettid(); // Android specific function to get thread ID - int priority = -20; // Highest priority for nice value + int tid = gettid(); // Android specific function to get thread ID + int priority = -2; // android.os.Process.THREAD_PRIORITY_FOREGROUND if (setpriority(PRIO_PROCESS, tid, priority) != 0) { // setpriority sets errno on failure DBG("[sfizz] Cannot set current thread priority: " << strerror(errno));