Commit 50e969ef authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Simplify threads init

parent 0d7bc734
...@@ -151,14 +151,13 @@ libvlc_int_t * vlc_current_object( int i_object ) ...@@ -151,14 +151,13 @@ libvlc_int_t * vlc_current_object( int i_object )
*/ */
libvlc_int_t * libvlc_InternalCreate( void ) libvlc_int_t * libvlc_InternalCreate( void )
{ {
int i_ret;
libvlc_int_t * p_libvlc = NULL; libvlc_int_t * p_libvlc = NULL;
char *psz_env = NULL; char *psz_env = NULL;
/* vlc_threads_init *must* be the first internal call! No other call is /* vlc_threads_init *must* be the first internal call! No other call is
* allowed before the thread system has been initialized. */ * allowed before the thread system has been initialized. */
i_ret = vlc_threads_init( p_libvlc_global ); if( vlc_threads_init( p_libvlc_global ) )
if( i_ret < 0 ) return NULL; return NULL;
/* Now that the thread system is initialized, we don't have much, but /* Now that the thread system is initialized, we don't have much, but
* at least we have variables */ * at least we have variables */
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
* Global mutex for lazy initialization of the threads system * Global mutex for lazy initialization of the threads system
*****************************************************************************/ *****************************************************************************/
static volatile unsigned i_initializations = 0; static volatile unsigned i_initializations = 0;
static volatile int i_status = VLC_THREADS_UNINITIALIZED;
static vlc_object_t *p_root; static vlc_object_t *p_root;
#if defined( UNDER_CE ) #if defined( UNDER_CE )
...@@ -130,53 +129,32 @@ int __vlc_threads_init( vlc_object_t *p_this ) ...@@ -130,53 +129,32 @@ int __vlc_threads_init( vlc_object_t *p_this )
pthread_mutex_lock( &once_mutex ); pthread_mutex_lock( &once_mutex );
#endif #endif
if( i_status == VLC_THREADS_UNINITIALIZED ) if( i_initializations == 0 )
{ {
i_status = VLC_THREADS_PENDING;
/* We should be safe now. Do all the initialization stuff we want. */ /* We should be safe now. Do all the initialization stuff we want. */
p_libvlc_global->b_ready = false; p_libvlc_global->b_ready = false;
p_root = vlc_custom_create( VLC_OBJECT(p_libvlc_global), 0, p_root = vlc_custom_create( VLC_OBJECT(p_libvlc_global), 0,
VLC_OBJECT_GLOBAL, "global" ); VLC_OBJECT_GLOBAL, "global" );
if( p_root == NULL ) if( p_root == NULL )
i_ret = VLC_ENOMEM;
if( i_ret )
{
i_status = VLC_THREADS_ERROR;
}
else
{ {
i_initializations++; i_ret = VLC_ENOMEM;
i_status = VLC_THREADS_READY; goto out;
} }
vlc_threadvar_create( p_root, &msg_context_global_key ); vlc_threadvar_create( p_root, &msg_context_global_key );
} }
else i_initializations++;
{
/* Just increment the initialization count */
i_initializations++;
}
/* If we have lazy mutex initialization support, unlock the mutex; out:
* otherwize, do a naive wait loop. */ /* If we have lazy mutex initialization support, unlock the mutex.
* Otherwize, we are screwed. */
#if defined( UNDER_CE ) #if defined( UNDER_CE )
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( WIN32 ) #elif defined( WIN32 )
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( LIBVLC_USE_PTHREAD ) #elif defined( LIBVLC_USE_PTHREAD )
pthread_mutex_unlock( &once_mutex ); pthread_mutex_unlock( &once_mutex );
#endif #endif
if( i_status != VLC_THREADS_READY )
{
return VLC_ETHREAD;
}
return i_ret; return i_ret;
} }
...@@ -195,15 +173,9 @@ int __vlc_threads_end( vlc_object_t *p_this ) ...@@ -195,15 +173,9 @@ int __vlc_threads_end( vlc_object_t *p_this )
pthread_mutex_lock( &once_mutex ); pthread_mutex_lock( &once_mutex );
#endif #endif
if( i_initializations == 0 ) assert( i_initializations > 0 );
return VLC_EGENERIC; if( --i_initializations == 0 )
i_initializations--;
if( i_initializations == 0 )
{
i_status = VLC_THREADS_UNINITIALIZED;
vlc_object_release( p_root ); vlc_object_release( p_root );
}
#if defined( UNDER_CE ) #if defined( UNDER_CE )
#elif defined( WIN32 ) #elif defined( WIN32 )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment