Changeset 2f27884905b95e2480c90b1c98e5322ed08fee6b

Show
Ignore:
Timestamp:
14/10/02 21:04:51 (6 years ago)
Author:
Sam Hocevar <sam@videolan.org>
git-committer:
Sam Hocevar <sam@videolan.org> 1034622291 +0000
git-parent:

[bf7985b74afcef9103b35a3c47eeae5845ae681b]

git-author:
Sam Hocevar <sam@videolan.org> 1034622291 +0000
Message:
  • ./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.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/variables.h

    rbf7985b r2f27884  
    33 ***************************************************************************** 
    44 * Copyright (C) 2002 VideoLAN 
    5  * $Id: variables.h,v 1.2 2002/10/14 16:46:55 sam Exp $ 
     5 * $Id: variables.h,v 1.3 2002/10/14 19:04:51 sam Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    3232#define VLC_VAR_ADDRESS   0x0600 
    3333#define VLC_VAR_COMMAND   0x0700 
     34#define VLC_VAR_MUTEX     0x0800 
    3435 
    3536/***************************************************************************** 
     
    4647 
    4748    /* Lots of other things that can be added */ 
     49    int          i_usage; 
    4850    vlc_bool_t   b_set; 
    4951    vlc_bool_t   b_active; 
  • modules/misc/testsuite/test4.c

    r112187e r2f27884  
    33 ***************************************************************************** 
    44 * Copyright (C) 2002 VideoLAN 
    5  * $Id: test4.c,v 1.1 2002/10/14 16:34:17 sam Exp $ 
     5 * $Id: test4.c,v 1.2 2002/10/14 19:04:51 sam Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    229229    while( !p_this->b_die ) 
    230230    { 
    231         msleep( 1000 ); 
     231        msleep( 10000 ); 
    232232    } 
    233233 
  • src/misc/variables.c

    rbf7985b r2f27884  
    33 ***************************************************************************** 
    44 * Copyright (C) 2002 VideoLAN 
    5  * $Id: variables.c,v 1.2 2002/10/14 16:46:56 sam Exp $ 
     5 * $Id: variables.c,v 1.3 2002/10/14 19:04:51 sam Exp $ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    5050{ 
    5151    int i_new; 
     52    variable_t *p_var; 
    5253 
    5354    vlc_mutex_lock( &p_this->var_lock ); 
     55 
     56    /* FIXME: if the variable already exists, we don't duplicate it. But we 
     57     * duplicate the lookups. It's not that serious, but if anyone finds some 
     58     * time to rework Insert() so that only one lookup has to be done, feel 
     59     * free to do so. */ 
     60    i_new = Lookup( p_this->p_vars, p_this->i_vars, psz_name ); 
     61 
     62    if( i_new >= 0 ) 
     63    { 
     64        /* If the types differ, variable creation failed. */ 
     65        if( i_type != p_this->p_vars[i_new].i_type ) 
     66        { 
     67            vlc_mutex_unlock( &p_this->var_lock ); 
     68            return VLC_EBADVAR; 
     69        } 
     70 
     71        p_this->p_vars[i_new].i_usage++; 
     72        vlc_mutex_unlock( &p_this->var_lock ); 
     73        return VLC_SUCCESS; 
     74    } 
     75 
     76    i_new = Insert( p_this->p_vars, p_this->i_vars, psz_name ); 
    5477 
    5578    if( (p_this->i_vars & 15) == 15 ) 
     
    5881                                  (p_this->i_vars+17) * sizeof(variable_t) ); 
    5982    } 
    60  
    61     i_new = Insert( p_this->p_vars, p_this->i_vars, psz_name ); 
    6283 
    6384    memmove( p_this->p_vars + i_new + 1, 
     
    6586             (p_this->i_vars - i_new) * sizeof(variable_t) ); 
    6687 
    67     p_this->p_vars[i_new].i_hash = HashString( psz_name ); 
    68     p_this->p_vars[i_new].psz_name = strdup( psz_name ); 
    69  
    70     p_this->p_vars[i_new].i_type = i_type; 
    71     memset( &p_this->p_vars[i_new].val, 0, sizeof(vlc_value_t) ); 
    72  
    73     p_this->p_vars[i_new].b_set = VLC_FALSE; 
    74     p_this->p_vars[i_new].b_active = VLC_TRUE; 
     88    p_var = &p_this->p_vars[i_new]; 
     89 
     90    p_var->i_hash = HashString( psz_name ); 
     91    p_var->psz_name = strdup( psz_name ); 
     92 
     93    p_var->i_type = i_type; 
     94    memset( &p_var->val, 0, sizeof(vlc_value_t) ); 
     95 
     96    p_var->i_usage = 1; 
     97    p_var->b_set = VLC_FALSE; 
     98    p_var->b_active = VLC_TRUE; 
    7599 
    76100    p_this->i_vars++; 
     
    90114{ 
    91115    int i_del; 
     116    variable_t *p_var; 
    92117 
    93118    vlc_mutex_lock( &p_this->var_lock ); 
     
    102127    } 
    103128 
     129    p_var = &p_this->p_vars[i_del]; 
     130 
     131    if( p_var->i_usage > 1 ) 
     132    { 
     133        p_var->i_usage--; 
     134        vlc_mutex_unlock( &p_this->var_lock ); 
     135        return VLC_SUCCESS; 
     136    } 
     137 
    104138    /* Free value if needed */ 
    105     switch( p_this->p_vars[i_del].i_type ) 
     139    switch( p_var->i_type ) 
    106140    { 
    107141        case VLC_VAR_STRING: 
    108142        case VLC_VAR_MODULE: 
    109143        case VLC_VAR_FILE: 
    110             if( p_this->p_vars[i_del].b_set 
    111                  && p_this->p_vars[i_del].val.psz_string ) 
     144            if( p_var->b_set && p_var->val.psz_string ) 
    112145            { 
    113                 free( p_this->p_vars[i_del].val.psz_string ); 
     146                free( p_var->val.psz_string ); 
    114147            } 
    115148            break; 
    116149    } 
    117150 
    118     free( p_this->p_vars[i_del].psz_name ); 
     151    free( p_var->psz_name ); 
    119152 
    120153    memmove( p_this->p_vars + i_del,