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;
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__)
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.
*
#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)
# include <sched.h>
#endif
-
struct vlc_thread_boot
{
void * (*entry) (vlc_object_t *);
/* 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 )
/*** 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;