Commit 19adcbe5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

variables: use a binary search tree instead of a table

This makes insertion/deletion faster, and saves a lot of code
parent 6d6fcaba
......@@ -162,10 +162,9 @@ typedef struct vlc_object_internals_t
char *psz_name; /* given name */
/* Object variables */
variable_t **pp_vars;
void *var_root;
vlc_mutex_t var_lock;
vlc_cond_t var_wait;
int i_vars;
/* Thread properties, if any */
vlc_thread_t thread_id;
......
......@@ -54,6 +54,7 @@
# include <errno.h> /* ENOSYS */
#endif
#include <search.h>
#include <limits.h>
#include <assert.h>
......@@ -131,7 +132,7 @@ void *__vlc_custom_create( vlc_object_t *p_this, size_t i_size,
p_new->i_flags = p_this->i_flags
& (OBJECT_FLAGS_NODBG|OBJECT_FLAGS_QUIET|OBJECT_FLAGS_NOINTERACT);
p_priv->pp_vars = NULL;
p_priv->var_root = NULL;
if( p_this == NULL )
{
......@@ -281,12 +282,8 @@ static void vlc_object_destroy( vlc_object_t *p_this )
/* Any thread must have been cleaned up at this point. */
assert( !p_priv->b_thread );
/* Destroy the associated variables, starting from the end so that
* no memmove calls have to be done. */
while( p_priv->i_vars )
{
var_Destroy( p_this, p_priv->pp_vars[p_priv->i_vars - 1]->psz_name );
}
/* Destroy the associated variables. */
var_DestroyAll( p_this );
vlc_cond_destroy( &p_priv->var_wait );
vlc_mutex_destroy( &p_priv->var_lock );
......@@ -766,56 +763,13 @@ vlc_list_t *__vlc_list_children( vlc_object_t *obj )
return l;
}
/*****************************************************************************
* DumpCommand: print the current vlc structure
*****************************************************************************
* This function prints either an ASCII tree showing the connections between
* vlc objects, and additional information such as their refcount, thread ID,
* etc. (command "tree"), or the same data as a simple list (command "list").
*****************************************************************************/
static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
static void DumpVariable (const void *data, const VISIT which, const int depth)
{
(void)oldval; (void)p_data;
vlc_object_t *p_object = NULL;
if( *newval.psz_string )
{
/* try using the object's name to find it */
p_object = vlc_object_find_name( p_this, newval.psz_string,
FIND_ANYWHERE );
if( !p_object )
{
return VLC_ENOOBJ;
}
}
libvlc_lock (p_this->p_libvlc);
if( *psz_cmd == 't' )
{
char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
if( !p_object )
p_object = VLC_OBJECT(p_this->p_libvlc);
psz_foo[0] = '|';
DumpStructure( p_object, 0, psz_foo );
}
else if( *psz_cmd == 'v' )
{
int i;
if( !p_object )
p_object = p_this->p_libvlc ? VLC_OBJECT(p_this->p_libvlc) : p_this;
PrintObject( p_object, "" );
if (which != postorder && which != leaf)
return;
(void) depth;
vlc_mutex_lock( &vlc_internals( p_object )->var_lock );
if( !vlc_internals( p_object )->i_vars )
printf( " `-o No variables\n" );
for( i = 0; i < vlc_internals( p_object )->i_vars; i++ )
{
const variable_t *p_var = vlc_internals( p_object )->pp_vars[i];
const variable_t *p_var = *(const variable_t **)data;
const char *psz_type = "unknown";
switch( p_var->i_type & VLC_VAR_TYPE )
......@@ -840,9 +794,7 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
MYCASE( LIST, "list" );
#undef MYCASE
}
printf( " %c-o \"%s\" (%s",
i + 1 == vlc_internals( p_object )->i_vars ? '`' : '|',
p_var->psz_name, psz_type );
printf( " *-o \"%s\" (%s", p_var->psz_name, psz_type );
if( p_var->psz_text )
printf( ", %s", p_var->psz_text );
printf( ")" );
......@@ -880,7 +832,54 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
break;
}
printf( "\n" );
}
/*****************************************************************************
* DumpCommand: print the current vlc structure
*****************************************************************************
* This function prints either an ASCII tree showing the connections between
* vlc objects, and additional information such as their refcount, thread ID,
* etc. (command "tree"), or the same data as a simple list (command "list").
*****************************************************************************/
static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
(void)oldval; (void)p_data;
vlc_object_t *p_object = NULL;
if( *newval.psz_string )
{
/* try using the object's name to find it */
p_object = vlc_object_find_name( p_this, newval.psz_string,
FIND_ANYWHERE );
if( !p_object )
{
return VLC_ENOOBJ;
}
}
libvlc_lock (p_this->p_libvlc);
if( *psz_cmd == 't' )
{
char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
if( !p_object )
p_object = VLC_OBJECT(p_this->p_libvlc);
psz_foo[0] = '|';
DumpStructure( p_object, 0, psz_foo );
}
else if( *psz_cmd == 'v' )
{
if( !p_object )
p_object = p_this->p_libvlc ? VLC_OBJECT(p_this->p_libvlc) : p_this;
PrintObject( p_object, "" );
vlc_mutex_lock( &vlc_internals( p_object )->var_lock );
if( vlc_internals( p_object )->var_root == NULL )
printf( " `-o No variables\n" );
else
twalk( vlc_internals( p_object )->var_root, DumpVariable );
vlc_mutex_unlock( &vlc_internals( p_object )->var_lock );
}
libvlc_unlock (p_this->p_libvlc);
......
This diff is collapsed.
......@@ -43,20 +43,18 @@ typedef struct variable_ops_t
*/
struct variable_t
{
char * psz_name; /**< The variable unique name (must be first) */
/** The variable's exported value */
vlc_value_t val;
char * psz_name; /**< The variable unique name */
uint32_t i_hash; /**< (almost) unique hashed value */
int i_type; /**< The type of the variable */
/** The variable display name, mainly for use by the interfaces */
char * psz_text;
const variable_ops_t *ops;
/** Creation count: we only destroy the variable if it reaches 0 */
int i_usage;
int i_type; /**< The type of the variable */
unsigned i_usage; /**< Reference count */
/** If the variable has min/max/step values */
vlc_value_t min, max, step;
......@@ -77,4 +75,7 @@ struct variable_t
/** Array of registered callbacks */
callback_entry_t * p_entries;
};
extern void var_DestroyAll( vlc_object_t * );
#endif
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