From aa47b1621816c96eff4d6c7edb7b4859192013a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Fri, 6 Jun 2008 17:48:48 +0300 Subject: [PATCH] Rescale POSIX realtime priorities within a portable range POSIX warrants at least 32 priorities from sched_get_priority_min(SCHED_RR) to sched_get_priority_max(SCHED_RR). We were previously relying on 41 priorities, from 0 to 40. --- include/vlc_threads.h | 12 ++++++------ src/misc/threads.c | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/vlc_threads.h b/include/vlc_threads.h index 3a04143799..9cd09408b5 100644 --- a/include/vlc_threads.h +++ b/include/vlc_threads.h @@ -78,12 +78,12 @@ # define VLC_THREAD_PRIORITY_HIGHEST 15 #elif defined(LIBVLC_USE_PTHREAD) -# define VLC_THREAD_PRIORITY_LOW 0 -# define VLC_THREAD_PRIORITY_INPUT 20 -# define VLC_THREAD_PRIORITY_AUDIO 10 -# define VLC_THREAD_PRIORITY_VIDEO 0 -# define VLC_THREAD_PRIORITY_OUTPUT 30 -# define VLC_THREAD_PRIORITY_HIGHEST 40 +# define VLC_THREAD_PRIORITY_LOW 0 +# define VLC_THREAD_PRIORITY_INPUT 10 +# define VLC_THREAD_PRIORITY_AUDIO 5 +# define VLC_THREAD_PRIORITY_VIDEO 0 +# define VLC_THREAD_PRIORITY_OUTPUT 15 +# define VLC_THREAD_PRIORITY_HIGHEST 20 #elif defined(WIN32) || defined(UNDER_CE) /* Define different priorities for WinNT/2K/XP and Win9x/Me */ diff --git a/src/misc/threads.c b/src/misc/threads.c index 11b3d478fd..90c6029ef5 100644 --- a/src/misc/threads.c +++ b/src/misc/threads.c @@ -48,6 +48,8 @@ static volatile unsigned i_initializations = 0; #if defined( LIBVLC_USE_PTHREAD ) +# include + static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER; #endif @@ -520,8 +522,10 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line pthread_attr_setschedpolicy (&attr, SCHED_OTHER); else { - struct sched_param param = { .sched_priority = +i_priority, }; - pthread_attr_setschedpolicy (&attr, SCHED_OTHER); + struct sched_param param = { .sched_priority = i_priority, }; + + param.sched_priority += sched_get_priority_min (SCHED_RR); + pthread_attr_setschedpolicy (&attr, SCHED_RR); pthread_attr_setschedparam (&attr, ¶m); } } -- 2.39.2