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

Hide global object within the thread and object subsystem

parent 4db976d9
...@@ -50,18 +50,6 @@ VLC_EXPORT( int, __vlc_thread_set_priority, ( vlc_object_t *, const char *, int ...@@ -50,18 +50,6 @@ VLC_EXPORT( int, __vlc_thread_set_priority, ( vlc_object_t *, const char *, int
VLC_EXPORT( void, __vlc_thread_ready, ( vlc_object_t * ) ); VLC_EXPORT( void, __vlc_thread_ready, ( vlc_object_t * ) );
VLC_EXPORT( void, __vlc_thread_join, ( vlc_object_t *, const char *, int ) ); VLC_EXPORT( void, __vlc_thread_join, ( vlc_object_t *, const char *, int ) );
/*****************************************************************************
* vlc_threads_init: initialize threads system
*****************************************************************************/
#define vlc_threads_init( P_THIS ) \
__vlc_threads_init( VLC_OBJECT(P_THIS) )
/*****************************************************************************
* vlc_threads_end: deinitialize threads system
*****************************************************************************/
#define vlc_threads_end( P_THIS ) \
__vlc_threads_end( VLC_OBJECT(P_THIS) )
/***************************************************************************** /*****************************************************************************
* vlc_mutex_init: initialize a mutex * vlc_mutex_init: initialize a mutex
*****************************************************************************/ *****************************************************************************/
......
...@@ -98,8 +98,6 @@ ...@@ -98,8 +98,6 @@
/***************************************************************************** /*****************************************************************************
* The evil global variable. We handle it with care, don't worry. * The evil global variable. We handle it with care, don't worry.
*****************************************************************************/ *****************************************************************************/
static libvlc_global_data_t libvlc_global;
static libvlc_global_data_t *p_libvlc_global = &libvlc_global;
static libvlc_int_t * p_static_vlc = NULL; static libvlc_int_t * p_static_vlc = NULL;
static volatile unsigned int i_instances = 0; static volatile unsigned int i_instances = 0;
...@@ -128,11 +126,6 @@ static int VerboseCallback( vlc_object_t *, char const *, ...@@ -128,11 +126,6 @@ static int VerboseCallback( vlc_object_t *, char const *,
static void InitDeviceValues( libvlc_int_t * ); static void InitDeviceValues( libvlc_int_t * );
libvlc_global_data_t *vlc_global( void )
{
return p_libvlc_global;
}
/***************************************************************************** /*****************************************************************************
* vlc_current_object: return the current object. * vlc_current_object: return the current object.
***************************************************************************** *****************************************************************************
...@@ -156,9 +149,10 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -156,9 +149,10 @@ libvlc_int_t * libvlc_InternalCreate( void )
/* 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. */
if( vlc_threads_init( p_libvlc_global ) ) if (vlc_threads_init ())
return NULL; return NULL;
libvlc_global_data_t *p_libvlc_global = vlc_global();
/* 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 */
vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
...@@ -230,6 +224,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -230,6 +224,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
const char *ppsz_argv[] ) const char *ppsz_argv[] )
{ {
libvlc_global_data_t *p_libvlc_global = vlc_global();
char p_capabilities[200]; char p_capabilities[200];
char * p_tmp = NULL; char * p_tmp = NULL;
char * psz_modules = NULL; char * psz_modules = NULL;
...@@ -1108,7 +1103,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release ) ...@@ -1108,7 +1103,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
/* Stop thread system: last one out please shut the door! /* Stop thread system: last one out please shut the door!
* The number of initializations of the thread system is counted, we * The number of initializations of the thread system is counted, we
* can call this each time */ * can call this each time */
vlc_threads_end( p_libvlc_global ); vlc_threads_end ();
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1136,7 +1131,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, ...@@ -1136,7 +1131,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc,
} }
#ifndef WIN32 #ifndef WIN32
if( p_libvlc_global->b_daemon && b_block && !psz_module ) if( vlc_global()->b_daemon && b_block && !psz_module )
{ {
/* Daemon mode hack. /* Daemon mode hack.
* We prefer the dummy interface if none is specified. */ * We prefer the dummy interface if none is specified. */
......
...@@ -56,8 +56,8 @@ VLC_EXPORT( const char * , system_VLCPath, (void)); ...@@ -56,8 +56,8 @@ VLC_EXPORT( const char * , system_VLCPath, (void));
/* /*
* Threads subsystem * Threads subsystem
*/ */
int __vlc_threads_init( vlc_object_t * ); int vlc_threads_init( void );
int __vlc_threads_end( vlc_object_t * ); void vlc_threads_end( void );
/** The global thread var for msg stack context /** The global thread var for msg stack context
* We store this as a static global variable so we don't need a vlc_object_t * We store this as a static global variable so we don't need a vlc_object_t
......
...@@ -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 vlc_object_t *p_root;
#if defined( UNDER_CE ) #if defined( UNDER_CE )
#elif defined( WIN32 ) #elif defined( WIN32 )
...@@ -54,6 +53,20 @@ static vlc_object_t *p_root; ...@@ -54,6 +53,20 @@ static vlc_object_t *p_root;
static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif #endif
/**
* Global process-wide VLC object.
* Contains inter-instance data, such as the module cache and global mutexes.
*/
static vlc_object_t *p_root;
static libvlc_global_data_t libvlc_global;
libvlc_global_data_t *vlc_global( void )
{
assert( i_initializations > 0 );
return &libvlc_global;
}
vlc_threadvar_t msg_context_global_key; vlc_threadvar_t msg_context_global_key;
#if defined(LIBVLC_USE_PTHREAD) #if defined(LIBVLC_USE_PTHREAD)
...@@ -115,9 +128,8 @@ void vlc_pthread_fatal (const char *action, int error, ...@@ -115,9 +128,8 @@ void vlc_pthread_fatal (const char *action, int error,
* keep the library really thread-safe. Some architectures don't support this * keep the library really thread-safe. Some architectures don't support this
* and thus do not guarantee the complete reentrancy. * and thus do not guarantee the complete reentrancy.
*****************************************************************************/ *****************************************************************************/
int __vlc_threads_init( vlc_object_t *p_this ) int vlc_threads_init( void )
{ {
libvlc_global_data_t *p_libvlc_global = (libvlc_global_data_t *)p_this;
int i_ret = VLC_SUCCESS; int i_ret = VLC_SUCCESS;
/* If we have lazy mutex initialization, use it. Otherwise, we just /* If we have lazy mutex initialization, use it. Otherwise, we just
...@@ -132,9 +144,9 @@ int __vlc_threads_init( vlc_object_t *p_this ) ...@@ -132,9 +144,9 @@ int __vlc_threads_init( vlc_object_t *p_this )
if( i_initializations == 0 ) if( i_initializations == 0 )
{ {
/* 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; libvlc_global.b_ready = false;
p_root = vlc_custom_create( VLC_OBJECT(p_libvlc_global), 0, p_root = vlc_custom_create( VLC_OBJECT(&libvlc_global), 0,
VLC_OBJECT_GLOBAL, "global" ); VLC_OBJECT_GLOBAL, "global" );
if( p_root == NULL ) if( p_root == NULL )
{ {
...@@ -163,9 +175,8 @@ out: ...@@ -163,9 +175,8 @@ out:
***************************************************************************** *****************************************************************************
* FIXME: This function is far from being threadsafe. * FIXME: This function is far from being threadsafe.
*****************************************************************************/ *****************************************************************************/
int __vlc_threads_end( vlc_object_t *p_this ) void vlc_threads_end( void )
{ {
(void)p_this;
#if defined( UNDER_CE ) #if defined( UNDER_CE )
#elif defined( WIN32 ) #elif defined( WIN32 )
#elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( HAVE_KERNEL_SCHEDULER_H )
...@@ -183,7 +194,6 @@ int __vlc_threads_end( vlc_object_t *p_this ) ...@@ -183,7 +194,6 @@ int __vlc_threads_end( vlc_object_t *p_this )
#elif defined( LIBVLC_USE_PTHREAD ) #elif defined( LIBVLC_USE_PTHREAD )
pthread_mutex_unlock( &once_mutex ); pthread_mutex_unlock( &once_mutex );
#endif #endif
return VLC_SUCCESS;
} }
#ifdef __linux__ #ifdef __linux__
......
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