[vlc-devel] commit: Allocate global object as the others - not statically anymore ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat May 3 11:49:59 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Sat May  3 12:34:11 2008 +0300| [830bfb51bcd76d72fb9849281dde281018e0095f]

Allocate global object as the others - not statically anymore

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=830bfb51bcd76d72fb9849281dde281018e0095f
---

 src/misc/objects.c |   14 +++++---------
 src/misc/threads.c |   16 ++++++++--------
 2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index 3207355..dc9c09f 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -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 );
 
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 3af6d5d..c0d1b08 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -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 )




More information about the vlc-devel mailing list