mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:35:06 -05:00
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:
committed by
Miroslav Lichvar
parent
2ddd0ae231
commit
69c6dffd63
11
sys_linux.c
11
sys_linux.c
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user