]> git.sesse.net Git - vlc/commitdiff
vlc_clone(): abide by --rt-priority and --rt-offset
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 25 Jul 2009 13:21:18 +0000 (16:21 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 25 Jul 2009 13:21:18 +0000 (16:21 +0300)
This avoids using real-time when not asked. It should also fix a
pthread_create() permission failure on FreeBSD (Linux seems to ignore
this error silently).

src/libvlc.c
src/libvlc.h
src/misc/pthread.c
src/misc/threads.c
src/misc/w32thread.c

index f0971a934ca1da948a374dd43dc158bd827e00c8..415d9d9f716ca3566957e5a8e8589be04e31e6e0 100644 (file)
@@ -733,6 +733,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         var_SetInteger( p_libvlc, "verbose", -1 );
         priv->i_verbose = -1;
     }
+    vlc_threads_setup( p_libvlc );
 
     if( priv->b_color )
         priv->b_color = config_GetInt( p_libvlc, "color" ) > 0;
index edd832ba31b2d23a6036f7fbb98c73d79b1bdfdc..15a8d2150faa06a079e59840451b5d8df819be28 100644 (file)
@@ -62,6 +62,8 @@ vlc_list_t *vlc_list_find( vlc_object_t *, int, int );
 void vlc_thread_cancel (vlc_object_t *);
 int vlc_object_waitpipe (vlc_object_t *obj);
 
+void vlc_threads_setup (libvlc_int_t *);
+
 void vlc_trace (const char *fn, const char *file, unsigned line);
 #define vlc_backtrace() vlc_trace(__func__, __FILE__, __LINE__)
 
index 14a48ad21be1f0037b115705b6f11b4dc2706701..644bf50f9333223b1de3dd28b85e7299bf1c1aaf 100644 (file)
@@ -461,6 +461,31 @@ void *vlc_threadvar_get (vlc_threadvar_t key)
     return pthread_getspecific (key);
 }
 
+static bool rt_priorities = false;
+static int rt_offset;
+
+void vlc_threads_setup (libvlc_int_t *p_libvlc)
+{
+    static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+    static bool initialized = false;
+
+    vlc_mutex_lock (&lock);
+    /* Initializes real-time priorities before any thread is created,
+     * just once per process. */
+    if (!initialized)
+    {
+#ifndef __APPLE__
+        if (config_GetInt (p_libvlc, "rt-priority"))
+#endif
+        {
+            rt_offset = config_GetInt (p_libvlc, "rt-offset");
+            rt_priorities = true;
+        }
+        initialized = true;
+    }
+    vlc_mutex_unlock (&lock);
+}
+
 /**
  * Creates and starts new thread.
  *
@@ -504,8 +529,9 @@ int vlc_clone (vlc_thread_t *p_handle, void * (*entry) (void *), void *data,
 #if defined (_POSIX_PRIORITY_SCHEDULING) && (_POSIX_PRIORITY_SCHEDULING >= 0) \
  && defined (_POSIX_THREAD_PRIORITY_SCHEDULING) \
  && (_POSIX_THREAD_PRIORITY_SCHEDULING >= 0)
+    if (rt_priorities)
     {
-        struct sched_param sp = { .sched_priority = priority, };
+        struct sched_param sp = { .sched_priority = priority + rt_offset, };
         int policy;
 
         if (sp.sched_priority <= 0)
index 1999c9ec4c91725d82499c83ecd1f0786be4e1cd..0f9821fb8d19c6e282e5e6edb9c339ce82572a76 100644 (file)
@@ -41,7 +41,6 @@
 # include <sched.h>
 #endif
 
-
 struct vlc_thread_boot
 {
     void * (*entry) (vlc_object_t *);
@@ -84,17 +83,6 @@ int vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line,
     /* Make sure we don't re-create a thread if the object has already one */
     assert( !p_priv->b_thread );
 
-#if defined( LIBVLC_USE_PTHREAD )
-#ifndef __APPLE__
-    if( config_GetInt( p_this, "rt-priority" ) > 0 )
-#endif
-    {
-        /* Hack to avoid error msg */
-        if( config_GetType( p_this, "rt-offset" ) )
-            i_priority += config_GetInt( p_this, "rt-offset" );
-    }
-#endif
-
     p_priv->b_thread = true;
     i_ret = vlc_clone( &p_priv->thread_id, thread_entry, boot, i_priority );
     if( i_ret == 0 )
index 96c0a88007a3296b370174ea4776cb3e05baef84..a2ef9eca272ee5e561154152fa1983a733891c94 100644 (file)
@@ -402,6 +402,11 @@ void *vlc_threadvar_get (vlc_threadvar_t key)
 
 
 /*** Threads ***/
+void vlc_threads_setup (libvlc_int_t *p_libvlc)
+{
+    (void) p_libvlc;
+}
+
 static unsigned __stdcall vlc_entry (void *data)
 {
     vlc_cancel_t cancel_data = VLC_CANCEL_INIT;