Commit 2f278849 authored by Sam Hocevar's avatar Sam Hocevar

* ./modules/misc/testsuite/test4.c: made the 4th test less CPU intensive

    by making the spawned threads wait a bit longer.
  * ./src/misc/variables.c: added a usage count to the variables; trying to
    create a variable with the same name only increments its refcount.
parent bf7985b7
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* variables.h: variables handling * variables.h: variables handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: variables.h,v 1.2 2002/10/14 16:46:55 sam Exp $ * $Id: variables.h,v 1.3 2002/10/14 19:04:51 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define VLC_VAR_TIME 0x0500 #define VLC_VAR_TIME 0x0500
#define VLC_VAR_ADDRESS 0x0600 #define VLC_VAR_ADDRESS 0x0600
#define VLC_VAR_COMMAND 0x0700 #define VLC_VAR_COMMAND 0x0700
#define VLC_VAR_MUTEX 0x0800
/***************************************************************************** /*****************************************************************************
* vlc_value_t is the common union for variable values; variable_t is the * vlc_value_t is the common union for variable values; variable_t is the
...@@ -45,6 +46,7 @@ struct variable_t ...@@ -45,6 +46,7 @@ struct variable_t
vlc_value_t val; vlc_value_t val;
/* Lots of other things that can be added */ /* Lots of other things that can be added */
int i_usage;
vlc_bool_t b_set; vlc_bool_t b_set;
vlc_bool_t b_active; vlc_bool_t b_active;
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* test4.c : Miscellaneous stress tests module for vlc * test4.c : Miscellaneous stress tests module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: test4.c,v 1.1 2002/10/14 16:34:17 sam Exp $ * $Id: test4.c,v 1.2 2002/10/14 19:04:51 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -228,7 +228,7 @@ static void * Dummy( vlc_object_t *p_this ) ...@@ -228,7 +228,7 @@ static void * Dummy( vlc_object_t *p_this )
while( !p_this->b_die ) while( !p_this->b_die )
{ {
msleep( 1000 ); msleep( 10000 );
} }
for( i = MAXOBJ/MAXTH; i--; ) for( i = MAXOBJ/MAXTH; i--; )
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* variables.c: routines for object variables handling * variables.c: routines for object variables handling
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: variables.c,v 1.2 2002/10/14 16:46:56 sam Exp $ * $Id: variables.c,v 1.3 2002/10/14 19:04:51 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -49,29 +49,53 @@ static int LookupInner ( variable_t *, int, u32 ); ...@@ -49,29 +49,53 @@ static int LookupInner ( variable_t *, int, u32 );
int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
{ {
int i_new; int i_new;
variable_t *p_var;
vlc_mutex_lock( &p_this->var_lock ); vlc_mutex_lock( &p_this->var_lock );
/* FIXME: if the variable already exists, we don't duplicate it. But we
* duplicate the lookups. It's not that serious, but if anyone finds some
* time to rework Insert() so that only one lookup has to be done, feel
* free to do so. */
i_new = Lookup( p_this->p_vars, p_this->i_vars, psz_name );
if( i_new >= 0 )
{
/* If the types differ, variable creation failed. */
if( i_type != p_this->p_vars[i_new].i_type )
{
vlc_mutex_unlock( &p_this->var_lock );
return VLC_EBADVAR;
}
p_this->p_vars[i_new].i_usage++;
vlc_mutex_unlock( &p_this->var_lock );
return VLC_SUCCESS;
}
i_new = Insert( p_this->p_vars, p_this->i_vars, psz_name );
if( (p_this->i_vars & 15) == 15 ) if( (p_this->i_vars & 15) == 15 )
{ {
p_this->p_vars = realloc( p_this->p_vars, p_this->p_vars = realloc( p_this->p_vars,
(p_this->i_vars+17) * sizeof(variable_t) ); (p_this->i_vars+17) * sizeof(variable_t) );
} }
i_new = Insert( p_this->p_vars, p_this->i_vars, psz_name );
memmove( p_this->p_vars + i_new + 1, memmove( p_this->p_vars + i_new + 1,
p_this->p_vars + i_new, p_this->p_vars + i_new,
(p_this->i_vars - i_new) * sizeof(variable_t) ); (p_this->i_vars - i_new) * sizeof(variable_t) );
p_this->p_vars[i_new].i_hash = HashString( psz_name ); p_var = &p_this->p_vars[i_new];
p_this->p_vars[i_new].psz_name = strdup( psz_name );
p_this->p_vars[i_new].i_type = i_type; p_var->i_hash = HashString( psz_name );
memset( &p_this->p_vars[i_new].val, 0, sizeof(vlc_value_t) ); p_var->psz_name = strdup( psz_name );
p_this->p_vars[i_new].b_set = VLC_FALSE; p_var->i_type = i_type;
p_this->p_vars[i_new].b_active = VLC_TRUE; memset( &p_var->val, 0, sizeof(vlc_value_t) );
p_var->i_usage = 1;
p_var->b_set = VLC_FALSE;
p_var->b_active = VLC_TRUE;
p_this->i_vars++; p_this->i_vars++;
...@@ -89,6 +113,7 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) ...@@ -89,6 +113,7 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) int __var_Destroy( vlc_object_t *p_this, const char *psz_name )
{ {
int i_del; int i_del;
variable_t *p_var;
vlc_mutex_lock( &p_this->var_lock ); vlc_mutex_lock( &p_this->var_lock );
...@@ -101,21 +126,29 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) ...@@ -101,21 +126,29 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name )
return VLC_ENOVAR; return VLC_ENOVAR;
} }
p_var = &p_this->p_vars[i_del];
if( p_var->i_usage > 1 )
{
p_var->i_usage--;
vlc_mutex_unlock( &p_this->var_lock );
return VLC_SUCCESS;
}
/* Free value if needed */ /* Free value if needed */
switch( p_this->p_vars[i_del].i_type ) switch( p_var->i_type )
{ {
case VLC_VAR_STRING: case VLC_VAR_STRING:
case VLC_VAR_MODULE: case VLC_VAR_MODULE:
case VLC_VAR_FILE: case VLC_VAR_FILE:
if( p_this->p_vars[i_del].b_set if( p_var->b_set && p_var->val.psz_string )
&& p_this->p_vars[i_del].val.psz_string )
{ {
free( p_this->p_vars[i_del].val.psz_string ); free( p_var->val.psz_string );
} }
break; break;
} }
free( p_this->p_vars[i_del].psz_name ); free( p_var->psz_name );
memmove( p_this->p_vars + i_del, memmove( p_this->p_vars + i_del,
p_this->p_vars + i_del + 1, p_this->p_vars + i_del + 1,
......
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