Commit 3ca7825a authored by Sam Hocevar's avatar Sam Hocevar

* ./include/vlc_threads_funcs.h, ./src/misc/threads.c: eradicated

    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.
parent ac811ffb
......@@ -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
*****************************************************************************/
......
......@@ -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 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; }
......
......@@ -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 );
......
......@@ -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
*****************************************************************************/
......
......@@ -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 );
......
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