sys_linux: use pthread_setschedparam instead of sched_setscheduler

Fix an issue with Linux and musl libc where sched_setscheduler is not
implemented. It seems that pthread_setschedparam is more widely
supported across different C libraries and OSs. For our use case, it
should make no difference which call is used.
This commit is contained in:
Stefan R. Filipek
2019-04-04 19:12:39 -04:00
committed by Miroslav Lichvar
parent 2ddd0ae231
commit 69c6dffd63
3 changed files with 18 additions and 11 deletions

View File

@@ -33,7 +33,8 @@
#include <sys/utsname.h>
#if defined(HAVE_SCHED_SETSCHEDULER)
#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
# include <pthread.h>
# include <sched.h>
#endif
@@ -632,7 +633,7 @@ add_failed:
/* ================================================== */
#if defined(HAVE_SCHED_SETSCHEDULER)
#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
/* Install SCHED_FIFO real-time scheduler with specified priority */
void SYS_Linux_SetScheduler(int SchedPriority)
{
@@ -651,8 +652,8 @@ void SYS_Linux_SetScheduler(int SchedPriority)
else if ( SchedPriority < pmin ) {
sched.sched_priority = pmin;
}
if ( sched_setscheduler(0, SCHED_FIFO, &sched) == -1 ) {
LOG(LOGS_ERR, "sched_setscheduler() failed");
if ( pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched) == -1 ) {
LOG(LOGS_ERR, "pthread_setschedparam() failed");
}
else {
DEBUG_LOG("Enabled SCHED_FIFO with priority %d",
@@ -660,7 +661,7 @@ void SYS_Linux_SetScheduler(int SchedPriority)
}
}
}
#endif /* HAVE_SCHED_SETSCHEDULER */
#endif /* HAVE_PTHREAD_SETSCHEDPARAM */
#if defined(HAVE_MLOCKALL)
/* Lock the process into RAM so that it will never be swapped out */