]> git.sesse.net Git - vlc/commitdiff
Rescale POSIX realtime priorities within a portable range
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Fri, 6 Jun 2008 14:48:48 +0000 (17:48 +0300)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Fri, 6 Jun 2008 14:48:48 +0000 (17:48 +0300)
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
src/misc/threads.c

index 3a04143799f837031a502b556b3c8644dd71eaef..9cd09408b581ec0f14a7d34fb2dbdf4d3833a00f 100644 (file)
 #   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 */
index 11b3d478fd476a88fed11bbe6af5e0f439918f6a..90c6029ef545aeb5f87c85ab11eca36f4ac218ee 100644 (file)
@@ -48,6 +48,8 @@
 static volatile unsigned i_initializations = 0;
 
 #if defined( LIBVLC_USE_PTHREAD )
+# include <sched.h>
+
 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, &param);
         }
     }