Skip to content

Commit

Permalink
Fix Android thread priority
Browse files Browse the repository at this point in the history
Android threads are Linux threads which differ from the POSIX standard. Calling pthread_setschedparam does not produce the intended effect on Android.
  • Loading branch information
chucknology authored Jun 21, 2024
1 parent 806bf1d commit eff6354
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/sfizz/FilePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include <atomic_queue/defs.h>
#if defined(_WIN32)
#include <windows.h>
#elif defined(__ANDROID__)
#include <sys/resource.h>
#else
#include <pthread.h>
#endif
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eff6354

Please sign in to comment.