[vlc-devel] commit: vlc_clone(): abide by --rt-priority and --rt-offset ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Jul 25 15:29:41 CEST 2009


vlc | branch: 1.0-bugfix | Rémi Denis-Courmont <remi at remlab.net> | Sat Jul 25 16:29:00 2009 +0300| [3dae95cd74ea10043c3f4ceb0a5fbc5552095729] | committer: Rémi Denis-Courmont 

vlc_clone(): abide by --rt-priority and --rt-offset

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).
(cherry picked from commit f52524a211617ca4db4fa290b7a867836e59fb78)

Conflicts:

	src/misc/pthread.c
	src/misc/w32thread.c

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3dae95cd74ea10043c3f4ceb0a5fbc5552095729
---

 src/libvlc.c       |    1 +
 src/libvlc.h       |    2 ++
 src/misc/threads.c |   46 +++++++++++++++++++++++++++++++++-------------
 3 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index 322b0e9..b9be376 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -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;
diff --git a/src/libvlc.h b/src/libvlc.h
index 94c2130..16f9aee 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -64,6 +64,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__)
 
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 71d0afe..88381e2 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -743,6 +743,37 @@ static unsigned __stdcall vlc_entry (void *data)
 }
 #endif
 
+#if defined (LIBVLC_USE_PTHREAD)
+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);
+}
+#else
+void vlc_threads_setup (libvlc_int_t *p_libvlc)
+{
+    (void) p_libvlc;
+#endif
+
 /**
  * Creates and starts new thread.
  *
@@ -787,8 +818,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)
@@ -1044,7 +1076,6 @@ void vlc_testcancel (void)
 #endif
 }
 
-
 struct vlc_thread_boot
 {
     void * (*entry) (vlc_object_t *);
@@ -1087,17 +1118,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 )




More information about the vlc-devel mailing list