]> git.sesse.net Git - vlc/commitdiff
* ./include/vlc_threads_funcs.h, ./src/misc/threads.c: eradicated
authorSam Hocevar <sam@videolan.org>
Tue, 15 Oct 2002 08:35:24 +0000 (08:35 +0000)
committerSam Hocevar <sam@videolan.org>
Tue, 15 Oct 2002 08:35:24 +0000 (08:35 +0000)
    vlc_mutex_need() and vlc_mutex_unneed().
  * ./src/misc/variables.c: implemented VLC_VAR_MUTEX variables.
  * ./modules/misc/gtk_main.c, ./src/libvlc.c: replaced named mutexes with
    named mutex variables.

include/vlc_threads_funcs.h
modules/misc/gtk_main.c
src/libvlc.c
src/misc/threads.c
src/misc/variables.c

index d813a1c314b66344bc52dea2450bb7ca0b195bd2..a5ae6f5e294190d35102189f7da9236a0e8235c5 100644 (file)
@@ -3,7 +3,7 @@
  * This header provides a portable threads implementation.
  *****************************************************************************
  * Copyright (C) 1999, 2002 VideoLAN
- * $Id: vlc_threads_funcs.h,v 1.5 2002/10/04 18:07:21 sam Exp $
+ * $Id: vlc_threads_funcs.h,v 1.6 2002/10/15 08:35:24 sam Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@via.ecp.fr>
@@ -38,9 +38,6 @@ VLC_EXPORT( int,  __vlc_thread_create, ( vlc_object_t *, char *, int, char *, vo
 VLC_EXPORT( void, __vlc_thread_ready,  ( vlc_object_t * ) );
 VLC_EXPORT( void, __vlc_thread_join,   ( vlc_object_t *, char *, int ) );
 
-VLC_EXPORT( vlc_mutex_t *, __vlc_mutex_need,   ( vlc_object_t *, char * ) );
-VLC_EXPORT( void         , __vlc_mutex_unneed, ( vlc_object_t *, char * ) );
-
 /*****************************************************************************
  * vlc_threads_init: initialize threads system
  *****************************************************************************/
@@ -59,12 +56,6 @@ VLC_EXPORT( void         , __vlc_mutex_unneed, ( vlc_object_t *, char * ) );
 #define vlc_mutex_init( P_THIS, P_MUTEX )                                   \
     __vlc_mutex_init( VLC_OBJECT(P_THIS), P_MUTEX )
 
-/*****************************************************************************
- * vlc_mutex_need: create a global mutex from its name
- *****************************************************************************/
-#define vlc_mutex_need( P_THIS, P_NAME )                                    \
-    __vlc_mutex_need( VLC_OBJECT(P_THIS), P_NAME )
-
 /*****************************************************************************
  * vlc_mutex_lock: lock a mutex
  *****************************************************************************/
@@ -201,12 +192,6 @@ static inline int __vlc_mutex_unlock( char * psz_file, int i_line,
     return i_result;
 }
 
-/*****************************************************************************
- * vlc_mutex_unneed: destroycreate a global mutex from its name
- *****************************************************************************/
-#define vlc_mutex_unneed( P_THIS, P_NAME )                                  \
-    __vlc_mutex_unneed( VLC_OBJECT(P_THIS), P_NAME )
-
 /*****************************************************************************
  * vlc_mutex_destroy: destroy a mutex
  *****************************************************************************/
index 799cf7dd0ad75a9c6c8bfa97820745dcb1b91a5c..967eec3ca211b0139fa6c0cc172653eeb2fb2dce 100644 (file)
@@ -2,7 +2,7 @@
  * gtk_main.c : Gtk+ wrapper for gtk_main
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: gtk_main.c,v 1.9 2002/10/04 18:07:21 sam Exp $
+ * $Id: gtk_main.c,v 1.10 2002/10/15 08:35:24 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -42,23 +42,11 @@ static void Close   ( vlc_object_t * );
 
 static void GtkMain ( vlc_object_t * );
 
-/*****************************************************************************
- * The gtk_main_t object.
- *****************************************************************************/
-#define MAX_ATEXIT 10
-
-typedef struct gtk_main_t
-{
-    VLC_COMMON_MEMBERS
-
-} gtk_main_t;
-
 /*****************************************************************************
  * Local variables (mutex-protected).
  *****************************************************************************/
-static vlc_mutex_t * p_gtklock;
-static int           i_refcount = 0;
-static gtk_main_t *  p_gtk_main = NULL;
+static int            i_refcount = 0;
+static vlc_object_t * p_gtk_main = NULL;
 
 /*****************************************************************************
  * Module descriptor
@@ -81,20 +69,23 @@ vlc_module_end();
  *****************************************************************************/
 static int Open( vlc_object_t *p_this )
 {
+    vlc_value_t lockval;
+
     /* FIXME: put this in the module (de)initialization ASAP */
-    p_gtklock = vlc_mutex_need( p_this, "gtk" );
+    var_Create( p_this->p_libvlc, "gtk", VLC_VAR_MUTEX );
 
-    vlc_mutex_lock( p_gtklock );
+    var_Get( p_this->p_libvlc, "gtk", &lockval );
+    vlc_mutex_lock( lockval.p_address );
 
     if( i_refcount > 0 )
     {
         i_refcount++;
-        vlc_mutex_unlock( p_gtklock );
+        vlc_mutex_unlock( lockval.p_address );
 
         return VLC_SUCCESS;
     }
 
-    p_gtk_main = vlc_object_create( p_this, sizeof(gtk_main_t) );
+    p_gtk_main = vlc_object_create( p_this, VLC_OBJECT_GENERIC );
 
     /* Only initialize gthreads if it's the first time we do it */
     if( !g_thread_supported() )
@@ -109,13 +100,13 @@ static int Open( vlc_object_t *p_this )
     {
         vlc_object_destroy( p_gtk_main );
         i_refcount--;
-        vlc_mutex_unlock( p_gtklock );
-        vlc_mutex_unneed( p_this, "gtk" );
+        vlc_mutex_unlock( lockval.p_address );
+        var_Destroy( p_this->p_libvlc, "gtk" );
         return VLC_ETHREAD;
     }
 
     i_refcount++;
-    vlc_mutex_unlock( p_gtklock );
+    vlc_mutex_unlock( lockval.p_address );
 
     return VLC_SUCCESS;
 }
@@ -125,14 +116,17 @@ static int Open( vlc_object_t *p_this )
  *****************************************************************************/
 static void Close( vlc_object_t *p_this )
 {
-    vlc_mutex_lock( p_gtklock );
+    vlc_value_t lockval;
+
+    var_Get( p_this->p_libvlc, "gtk", &lockval );
+    vlc_mutex_lock( lockval.p_address );
 
     i_refcount--;
 
     if( i_refcount > 0 )
     {
-        vlc_mutex_unlock( p_gtklock );
-        vlc_mutex_unneed( p_this, "gtk" );
+        vlc_mutex_unlock( lockval.p_address );
+        var_Destroy( p_this->p_libvlc, "gtk" );
         return;
     }
 
@@ -142,8 +136,8 @@ static void Close( vlc_object_t *p_this )
     vlc_object_destroy( p_gtk_main );
     p_gtk_main = NULL;
 
-    vlc_mutex_unlock( p_gtklock );
-    vlc_mutex_unneed( p_this, "gtk" );
+    vlc_mutex_unlock( lockval.p_address );
+    var_Destroy( p_this->p_libvlc, "gtk" );
 }
 
 static gint foo( gpointer bar ) { return TRUE; }
index f07c7e9166d5acea1816b3c5065a8cab58f2ada3..1f1d4d8958d8e9c4606d0f74f8bd5bf7e9a1e80f 100644 (file)
@@ -2,7 +2,7 @@
  * libvlc.c: main libvlc source
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: libvlc.c,v 1.39 2002/10/14 16:46:55 sam Exp $
+ * $Id: libvlc.c,v 1.40 2002/10/15 08:35:24 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -125,7 +125,7 @@ int VLC_Create( void )
 {
     int i_ret;
     vlc_t * p_vlc = NULL;
-    vlc_mutex_t * p_libvlc_lock;
+    vlc_value_t lockval;
 
     /* vlc_threads_init *must* be the first internal call! No other call is
      * allowed before the thread system has been initialized. */
@@ -136,9 +136,10 @@ int VLC_Create( void )
     }
 
     /* Now that the thread system is initialized, we don't have much, but
-     * at least we have vlc_mutex_need */
-    p_libvlc_lock = vlc_mutex_need( &libvlc, "libvlc" );
-    vlc_mutex_lock( p_libvlc_lock );
+     * at least we have var_Create */
+    var_Create( &libvlc, "libvlc", VLC_VAR_MUTEX );
+    var_Get( &libvlc, "libvlc", &lockval );
+    vlc_mutex_lock( lockval.p_address );
     if( !libvlc.b_ready )
     {
         char *psz_env;
@@ -172,8 +173,8 @@ int VLC_Create( void )
 
         libvlc.b_ready = VLC_TRUE;
     }
-    vlc_mutex_unlock( p_libvlc_lock );
-    vlc_mutex_unneed( &libvlc, "libvlc" );
+    vlc_mutex_unlock( lockval.p_address );
+    var_Destroy( &libvlc, "libvlc" );
 
     /* Allocate a vlc object */
     p_vlc = vlc_object_create( &libvlc, VLC_OBJECT_VLC );
index 8ce3bd10c76a169e879e51a54cb6baa78351e3d4..9bfc174cd190c8efd487c12e35d9f0d8f0b44f05 100644 (file)
@@ -2,7 +2,7 @@
  * threads.c : threads implementation for the VideoLAN client
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
- * $Id: threads.c,v 1.21 2002/10/04 18:07:22 sam Exp $
+ * $Id: threads.c,v 1.22 2002/10/15 08:35:24 sam Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -321,99 +321,6 @@ int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
 #endif
 }
 
-/*****************************************************************************
- * vlc_mutex_need: create a global mutex from its name
- *****************************************************************************/
-vlc_mutex_t * __vlc_mutex_need( vlc_object_t *p_this, char *psz_name )
-{
-    vlc_namedmutex_t *p_named;
-
-    vlc_mutex_lock( &named_lock );
-
-    p_named = p_named_list;
-    while( p_named )
-    {
-        if( !strcmp( psz_name, p_named->psz_name ) )
-        {
-            break;
-        }
-        p_named = p_named->p_next;
-    }
-
-    if( p_named )
-    {
-        p_named->i_usage++;
-    }
-    else
-    {
-        p_named = malloc( sizeof( vlc_namedmutex_t ) );
-        vlc_mutex_init( p_this, &p_named->lock );
-        p_named->psz_name = strdup( psz_name );
-        p_named->i_usage = 1;
-        p_named->p_next = p_named_list;
-        p_named_list = p_named;
-    }
-
-    vlc_mutex_unlock( &named_lock );
-
-    return &p_named->lock;
-}
-
-/*****************************************************************************
- * vlc_mutex_unneed: destroy a global mutex from its name
- *****************************************************************************/
-void __vlc_mutex_unneed( vlc_object_t *p_this, char *psz_name )
-{
-    vlc_namedmutex_t *p_named, *p_prev;
-
-    vlc_mutex_lock( &named_lock );
-
-    p_named = p_named_list;
-    p_prev = NULL;
-    while( p_named )
-    {
-        if( !strcmp( psz_name, p_named->psz_name ) )
-        {
-            break;
-        }
-        p_prev = p_named;
-        p_named = p_named->p_next;
-    }
-
-    if( p_named )
-    {
-        p_named->i_usage--;
-
-        if( p_named->i_usage <= 0 )
-        {
-            /* Unlink named mutex */
-            if( p_prev )
-            {
-                p_prev->p_next = p_named->p_next;
-            }
-            else
-            {
-                p_named_list = p_named->p_next;
-            }
-
-            /* Release this lock as soon as possible */
-            vlc_mutex_unlock( &named_lock );
-
-            vlc_mutex_destroy( &p_named->lock );
-            free( p_named->psz_name );
-            free( p_named );
-
-            return;
-        }
-    }
-    else
-    {
-        msg_Err( p_this, "no named mutex called %s", psz_name );
-    }
-
-    vlc_mutex_unlock( &named_lock );
-}
-
 /*****************************************************************************
  * vlc_mutex_destroy: destroy a mutex, inner version
  *****************************************************************************/
index 1b1e4186df8c49b33e52702cd8cf89605b1ce551..f8e9810e7efd9e399f39ccc91498c9eeaed2972d 100644 (file)
@@ -2,7 +2,7 @@
  * variables.c: routines for object variables handling
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: variables.c,v 1.3 2002/10/14 19:04:51 sam Exp $
+ * $Id: variables.c,v 1.4 2002/10/15 08:35:24 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -85,6 +85,8 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
              p_this->p_vars + i_new,
              (p_this->i_vars - i_new) * sizeof(variable_t) );
 
+    p_this->i_vars++;
+
     p_var = &p_this->p_vars[i_new];
 
     p_var->i_hash = HashString( psz_name );
@@ -97,7 +99,14 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
     p_var->b_set = VLC_FALSE;
     p_var->b_active = VLC_TRUE;
 
-    p_this->i_vars++;
+    switch( i_type )
+    {
+        case VLC_VAR_MUTEX:
+            p_var->val.p_address = malloc( sizeof(vlc_mutex_t) );
+            vlc_mutex_init( p_this, (vlc_mutex_t*)p_var->val.p_address );
+            p_var->b_set = VLC_TRUE;
+            break;
+    }
 
     vlc_mutex_unlock( &p_this->var_lock );
 
@@ -146,6 +155,11 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name )
                 free( p_var->val.psz_string );
             }
             break;
+
+        case VLC_VAR_MUTEX:
+            vlc_mutex_destroy( (vlc_mutex_t*)p_var->val.p_address );
+            free( p_var->val.p_address );
+            break;
     }
 
     free( p_var->psz_name );