]> git.sesse.net Git - vlc/blobdiff - src/misc/threads.c
threads: Make sure we don't re-create a thread if the object has already one.
[vlc] / src / misc / threads.c
index 8b503b709af9c91a001b7d9eb020b50f19af730c..9cac384deb65caebc5a68ef1508e18699abf5e15 100644 (file)
@@ -501,6 +501,9 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
 
     vlc_object_lock( p_this );
 
+    /* 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 )
     pthread_attr_t attr;
     pthread_attr_init (&attr);
@@ -622,6 +625,12 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
 {
     vlc_object_internals_t *p_priv = vlc_internals( p_this );
 
+    if( !p_priv->b_thread )
+    {
+        msg_Err( p_this, "couldn't set priority of non-existent thread" );
+        return ESRCH;
+    }
+
 #if defined( LIBVLC_USE_PTHREAD )
 # ifndef __APPLE__
     if( config_GetInt( p_this, "rt-priority" ) > 0 )
@@ -643,10 +652,8 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
             param.sched_priority = i_priority;
             i_policy = SCHED_RR;
         }
-        if( !p_priv->thread_id )
-            p_priv->thread_id = pthread_self();
         if( (i_error = pthread_setschedparam( p_priv->thread_id,
-                                               i_policy, &param )) )
+                                              i_policy, &param )) )
         {
             errno = i_error;
             msg_Warn( p_this, "couldn't set thread priority (%s:%d): %m",
@@ -658,8 +665,6 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
 #elif defined( WIN32 ) || defined( UNDER_CE )
     VLC_UNUSED( psz_file); VLC_UNUSED( i_line );
 
-    if( !p_priv->thread_id )
-        p_priv->thread_id = GetCurrentThread();
     if( !SetThreadPriority(p_priv->thread_id, i_priority) )
     {
         msg_Warn( p_this, "couldn't set a faster priority" );