]> git.sesse.net Git - vlc/commitdiff
Allocate global object as the others - not statically anymore
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 3 May 2008 09:34:11 +0000 (12:34 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 3 May 2008 09:34:11 +0000 (12:34 +0300)
src/misc/objects.c
src/misc/threads.c

index 3207355a372089525ee31fe5e0174a01c318c717..dc9c09f76a5f7ee39214ce5ec14c1ba80822f702 100644 (file)
@@ -115,13 +115,8 @@ void *vlc_custom_create( vlc_object_t *p_this, size_t i_size,
     if( p_priv == NULL )
         return NULL;
 
-    if( i_type == VLC_OBJECT_GLOBAL )
-        p_new = p_this;
-    else
-    {
-        assert (i_size >= sizeof (vlc_object_t));
-        p_new = (vlc_object_t *)(p_priv + 1);
-    }
+    assert (i_size >= sizeof (vlc_object_t));
+    p_new = (vlc_object_t *)(p_priv + 1);
 
     p_new->p_internals = p_priv;
     p_new->i_object_type = i_type;
@@ -137,8 +132,9 @@ void *vlc_custom_create( vlc_object_t *p_this, size_t i_size,
 
     p_new->psz_header = NULL;
 
-    p_new->i_flags |= p_this->i_flags
-        & (OBJECT_FLAGS_NODBG|OBJECT_FLAGS_QUIET|OBJECT_FLAGS_NOINTERACT);
+    if (p_this)
+        p_new->i_flags = p_this->i_flags
+            & (OBJECT_FLAGS_NODBG|OBJECT_FLAGS_QUIET|OBJECT_FLAGS_NOINTERACT);
 
     p_priv->p_vars = calloc( sizeof( variable_t ), 16 );
 
index 3af6d5dddf1321d2048c81652e7dded9cfbf6a1c..c0d1b0886007dac91a4a81941bd097ad9875494d 100644 (file)
@@ -57,13 +57,12 @@ static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
  * 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;
+static libvlc_global_data_t *p_root;
 
 libvlc_global_data_t *vlc_global( void )
 {
     assert( i_initializations > 0 );
-    return &libvlc_global;
+    return p_root;
 }
 
 
@@ -143,16 +142,16 @@ int vlc_threads_init( void )
 
     if( i_initializations == 0 )
     {
-        /* We should be safe now. Do all the initialization stuff we want. */
-        libvlc_global.b_ready = false;
-
-        p_root = vlc_custom_create( VLC_OBJECT(&libvlc_global), 0,
+        p_root = vlc_custom_create( NULL, sizeof( *p_root ),
                                     VLC_OBJECT_GLOBAL, "global" );
         if( p_root == NULL )
         {
             i_ret = VLC_ENOMEM;
             goto out;
         }
+
+        /* We should be safe now. Do all the initialization stuff we want. */
+        p_root->b_ready = false;
         vlc_threadvar_create( p_root, &msg_context_global_key );
     }
     i_initializations++;
@@ -185,8 +184,9 @@ void vlc_threads_end( void )
 #endif
 
     assert( i_initializations > 0 );
-    if( --i_initializations == 0 )
+    if( i_initializations == 0 )
         vlc_object_release( p_root );
+    i_initializations--;
 
 #if defined( UNDER_CE )
 #elif defined( WIN32 )