From a944e19331fb14e890610bf7e81d584c6ac2465b Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 19 Apr 2025 14:38:29 +1000 Subject: [PATCH] pthread: Add support for falling back to a non-realtime thread. MA_NO_PTHREAD_REALTIME_PRIORITY_FALLBACK can be used to disable this functionality for applications that have a hard requirement on a realtime thread. --- miniaudio.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/miniaudio.h b/miniaudio.h index 0b143f61..cf362fa5 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -16270,6 +16270,21 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority } if (result != 0) { + /* + There have been reports that attempting to create a realtime thread can sometimes fail. In this case, + fall back to a normal priority thread. + + I'm including a compile-time option here to disable this functionality for those who have a hard + requirement on realtime threads and would rather an explicit failure. + */ + #ifndef MA_NO_PTHREAD_REALTIME_PRIORITY_FALLBACK + { + if(result == EPERM && priority == ma_thread_priority_realtime) { + return ma_thread_create__posix(pThread, ma_thread_priority_normal, stackSize, entryProc, pData); + } + } + #endif + return ma_result_from_errno(result); }