boot->entry = func;
boot->object = p_this;
- 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 )
+ if (b_wait)
+ sem_init (&p_priv->thread_ready, 0, 0);
#ifndef __APPLE__
if( config_GetInt( p_this, "rt-priority" ) > 0 )
#endif
if( config_GetType( p_this, "rt-offset" ) )
i_priority += config_GetInt( p_this, "rt-offset" );
}
+#elif defined (WIN32)
+ if (b_wait)
+ p_priv->thread_ready = CreateEvent (NULL, TRUE, FALSE, NULL);
#endif
+ p_priv->b_thread = true;
i_ret = vlc_clone( &p_priv->thread_id, thread_entry, boot, i_priority );
if( i_ret == 0 )
{
+ msg_Dbg( p_this, "thread %lu (%s) created at priority %d (%s:%d)",
+ (unsigned long)p_priv->thread_id, psz_name, i_priority,
+ psz_file, i_line );
if( b_wait )
{
msg_Dbg( p_this, "waiting for thread initialization" );
- vlc_object_wait( p_this );
+#if defined (LIBVLC_USE_PTHREAD)
+ sem_wait (&p_priv->thread_ready);
+ sem_destroy (&p_priv->thread_ready);
+#elif defined (WIN32)
+ WaitForSingleObject (p_priv->thread_ready, INFINITE);
+ CloseHandle (p_priv->thread_ready);
+#endif
}
-
- p_priv->b_thread = true;
- msg_Dbg( p_this, "thread %lu (%s) created at priority %d (%s:%d)",
- (unsigned long)p_priv->thread_id, psz_name, i_priority,
- psz_file, i_line );
}
else
{
+ p_priv->b_thread = false;
errno = i_ret;
msg_Err( p_this, "%s thread could not be created at %s:%d (%m)",
psz_name, psz_file, i_line );
}
- vlc_object_unlock( p_this );
return i_ret;
}
+#undef vlc_thread_ready
+void vlc_thread_ready (vlc_object_t *obj)
+{
+ vlc_object_internals_t *priv = vlc_internals (obj);
+
+ assert (priv->b_thread);
+#if defined (LIBVLC_USE_PTHREAD)
+ assert (pthread_equal (pthread_self (), priv->thread_id));
+ sem_post (&priv->thread_ready);
+#elif defined (WIN32)
+ SetEvent (priv->thread_ready);
+#endif
+}
+
/*****************************************************************************
* vlc_thread_set_priority: set the priority of the current thread when we
* couldn't set it in vlc_thread_create (for instance for the main thread)