Changeset 8dba805732a431558c1218104dfeb667d9b5df63

Show
Ignore:
Timestamp:
05/16/08 18:01:19 (4 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1210953679 +0300
git-parent:

[414624cea784dc0c97bb99826bad98b3c95fda36]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1210949943 +0300
Message:

Hide i_children and pp_children away

They can only be read safely under the Big Structure Lock in
src/misc/objects.c, so it makes no sense for them to be public.

By the way, making i_children volatile wouldn't magically solve
thread-safety issues. The only correct use of volatile is in dealing
with asynchronous changes _within_ the same thread, such as signal
handling.

P.S.: I wish modules were not objects, and I wonder why they are
(they don't don't use threads, nor plugins, nor variables)

Files:

Legend:

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

    r9a719ad r8dba805  
    482482                                                                            \ 
    483483    vlc_object_t *  p_parent;                            /**< our parent */ \ 
    484     vlc_object_t ** pp_children;                       /**< our children */ \ 
    485     volatile int    i_children;                                             \ 
    486484                                                                            \ 
    487485    /* Private data */                                                      \ 
  • src/libvlc-common.c

    r4ec082c r8dba805  
    427427 
    428428    msg_Dbg( p_libvlc, "module bank initialized, found %i modules", 
    429              p_libvlc_global->p_module_bank->i_children ); 
     429             vlc_internals( p_libvlc_global->p_module_bank )->i_children ); 
    430430 
    431431    /* Check for help on modules */ 
  • src/libvlc.h

    rc79a340 r8dba805  
    182182    unsigned         i_refcount; 
    183183    vlc_destructor_t pf_destructor; 
     184 
     185    vlc_object_t   **pp_children; 
     186    int              i_children; 
    184187}; 
    185188 
  • src/misc/objects.c

    r73edaec r8dba805  
    160160    p_priv->b_thread = false; 
    161161    p_new->p_parent = NULL; 
    162     p_new->pp_children = NULL; 
    163     p_new->i_children = 0; 
     162    p_priv->pp_children = NULL; 
     163    p_priv->i_children = 0; 
    164164 
    165165    p_new->p_private = NULL; 
     
    323323 
    324324    /* Sanity checks */ 
    325     if( p_this->i_children ) 
     325    if( p_priv->i_children ) 
    326326    { 
    327327        int i; 
     
    330330                 "ERROR: cannot delete object (%i, %s) with %d children\n", 
    331331                 p_this->i_object_id, p_this->psz_object_name, 
    332                  p_this->i_children ); 
    333  
    334         for( i = 0; i < p_this->i_children; i++ ) 
     332                 p_priv->i_children ); 
     333 
     334        for( i = 0; i < p_priv->i_children; i++ ) 
    335335        { 
    336336            fprintf( stderr, 
    337337                     "ERROR: Remaining children object " 
    338338                     "(id:%i, type:%s, name:%s)\n", 
    339                      p_this->pp_children[i]->i_object_id, 
    340                      p_this->pp_children[i]->psz_object_type, 
    341                      p_this->pp_children[i]->psz_object_name ); 
     339                     p_priv->pp_children[i]->i_object_id, 
     340                     p_priv->pp_children[i]->psz_object_type, 
     341                     p_priv->pp_children[i]->psz_object_name ); 
    342342        } 
    343343        fflush(stderr); 
     
    653653 
    654654    if( p_this->i_object_type == VLC_OBJECT_LIBVLC ) 
    655         for( int i = 0; i < p_this->i_children ; i++ ) 
    656             vlc_object_kill( p_this->pp_children[i] ); 
     655        for( int i = 0; i < internals->i_children ; i++ ) 
     656            vlc_object_kill( internals->pp_children[i] ); 
    657657 
    658658    vlc_object_signal_unlocked( p_this ); 
     
    881881            vlc_object_detach_unlocked (p_this); 
    882882        /* Detach from children to protect against FIND_PARENT */ 
    883         for (int i = 0; i < p_this->i_children; i++) 
    884             p_this->pp_children[i]->p_parent = NULL; 
     883        for (int i = 0; i < internals->i_children; i++) 
     884            internals->pp_children[i]->p_parent = NULL; 
    885885    } 
    886886 
     
    909909 
    910910    /* Attach the child to its parent */ 
    911     INSERT_ELEM( p_parent->pp_children, p_parent->i_children, 
    912                  p_parent->i_children, p_this ); 
     911    vlc_object_internals_t *priv = vlc_internals( p_parent ); 
     912    INSERT_ELEM( priv->pp_children, priv->i_children, priv->i_children, 
     913                 p_this ); 
    913914 
    914915    vlc_mutex_unlock( &structure_lock ); 
     
    920921    assert (p_this->p_parent); 
    921922 
    922     vlc_object_t *p_parent = p_this->p_parent; 
     923    vlc_object_internals_t *priv = vlc_internals( p_this->p_parent ); 
     924 
    923925    int i_index, i; 
    924926 
     
    927929 
    928930    /* Remove all of p_parent's children which are p_this */ 
    929     for( i_index = p_parent->i_children ; i_index-- ; ) 
    930     { 
    931         if( p_parent->pp_children[i_index] == p_this ) 
    932         { 
    933             p_parent->i_children--; 
    934             for( i = i_index ; i < p_parent->i_children ; i++ ) 
    935             { 
    936                 p_parent->pp_children[i] = p_parent->pp_children[i+1]; 
    937             } 
    938         } 
    939     } 
    940  
    941     if( p_parent->i_children ) 
    942     { 
    943         p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children, 
    944                                p_parent->i_children * sizeof(vlc_object_t *) ); 
     931    for( i_index = priv->i_children ; i_index-- ; ) 
     932    { 
     933        if( priv->pp_children[i_index] == p_this ) 
     934        { 
     935            priv->i_children--; 
     936            for( i = i_index ; i < priv->i_children ; i++ ) 
     937                priv->pp_children[i] = priv->pp_children[i+1]; 
     938        } 
     939    } 
     940 
     941    if( priv->i_children ) 
     942    { 
     943        priv->pp_children = (vlc_object_t **)realloc( priv->pp_children, 
     944                               priv->i_children * sizeof(vlc_object_t *) ); 
    945945    } 
    946946    else 
    947947    { 
    948948        /* Special case - don't realloc() to zero to avoid leaking */ 
    949         free( p_parent->pp_children ); 
    950         p_parent->pp_children = NULL; 
     949        free( priv->pp_children ); 
     950        priv->pp_children = NULL; 
    951951    } 
    952952} 
     
    10301030{ 
    10311031    vlc_list_t *l; 
     1032    vlc_object_internals_t *priv = vlc_internals( obj ); 
    10321033 
    10331034    vlc_mutex_lock( &structure_lock ); 
    1034     l = NewList( obj->i_children ); 
     1035    l = NewList( priv->i_children ); 
    10351036    for (int i = 0; i < l->i_count; i++) 
    10361037    { 
    1037         vlc_object_yield( obj->pp_children[i] ); 
    1038         l->p_values[i].p_object = obj->pp_children[i]; 
     1038        vlc_object_yield( priv->pp_children[i] ); 
     1039        l->p_values[i].p_object = priv->pp_children[i]; 
    10391040    } 
    10401041    vlc_mutex_unlock( &structure_lock ); 
     
    13051306 
    13061307    case FIND_CHILD: 
    1307         for( i = p_this->i_children; i--; ) 
    1308         { 
    1309             p_tmp = p_this->pp_children[i]; 
     1308        for( i = vlc_internals( p_this )->i_children; i--; ) 
     1309        { 
     1310            p_tmp = vlc_internals( p_this )->pp_children[i]; 
    13101311            if( p_tmp->i_object_type == i_type ) 
    13111312            { 
     
    13131314                return p_tmp; 
    13141315            } 
    1315             else if( p_tmp->i_children ) 
     1316            else if( vlc_internals( p_tmp )->i_children ) 
    13161317            { 
    13171318                p_tmp = FindObject( p_tmp, i_type, i_mode ); 
     
    13591360 
    13601361    case FIND_CHILD: 
    1361         for( i = p_this->i_children; i--; ) 
    1362         { 
    1363             p_tmp = p_this->pp_children[i]; 
     1362        for( i = vlc_internals( p_this )->i_children; i--; ) 
     1363        { 
     1364            p_tmp = vlc_internals( p_this )->pp_children[i]; 
    13641365            if( p_tmp->psz_object_name 
    13651366                && !strcmp( p_tmp->psz_object_name, psz_name ) ) 
     
    13681369                return p_tmp; 
    13691370            } 
    1370             else if( p_tmp->i_children ) 
     1371            else if( vlc_internals( p_tmp )->i_children ) 
    13711372            { 
    13721373                p_tmp = FindObjectName( p_tmp, psz_name, i_mode ); 
     
    14021403 
    14031404    psz_children[0] = '\0'; 
    1404     switch( p_this->i_children ) 
     1405    switch( vlc_internals( p_this )->i_children ) 
    14051406    { 
    14061407        case 0: 
     
    14101411            break; 
    14111412        default: 
    1412             snprintf( psz_children, 19, ", %i children", p_this->i_children ); 
     1413            snprintf( psz_children, 19, ", %i children", 
     1414                      vlc_internals( p_this )->i_children ); 
    14131415            break; 
    14141416    } 
     
    14501452    } 
    14511453 
    1452     for( i = 0 ; i < p_this->i_children ; i++ ) 
     1454    for( i = 0 ; i < vlc_internals( p_this )->i_children ; i++ ) 
    14531455    { 
    14541456        if( i_level ) 
     
    14621464        } 
    14631465 
    1464         if( i == p_this->i_children - 1 ) 
     1466        if( i == vlc_internals( p_this )->i_children - 1 ) 
    14651467        { 
    14661468            psz_foo[i_level] = '`'; 
     
    14741476        psz_foo[i_level+2] = '\0'; 
    14751477 
    1476         DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo ); 
     1478        DumpStructure( vlc_internals( p_this )->pp_children[i], i_level + 2, 
     1479                       psz_foo ); 
    14771480    } 
    14781481} 
     
    15471550    int i, i_count = 0; 
    15481551 
    1549     for( i = 0; i < p_this->i_children; i++ ) 
    1550     { 
    1551         p_tmp = p_this->pp_children[i]; 
     1552    for( i = 0; i < vlc_internals( p_this )->i_children; i++ ) 
     1553    { 
     1554        p_tmp = vlc_internals( p_this )->pp_children[i]; 
    15521555 
    15531556        if( p_tmp->i_object_type == i_type ) 
     
    15551558            i_count++; 
    15561559        } 
    1557  
    1558         if( p_tmp->i_children ) 
    1559         { 
    1560             i_count += CountChildren( p_tmp, i_type ); 
    1561         } 
     1560        i_count += CountChildren( p_tmp, i_type ); 
    15621561    } 
    15631562 
     
    15701569    int i; 
    15711570 
    1572     for( i = 0; i < p_this->i_children; i++ ) 
    1573     { 
    1574         p_tmp = p_this->pp_children[i]; 
     1571    for( i = 0; i < vlc_internals( p_this )->i_children; i++ ) 
     1572    { 
     1573        p_tmp = vlc_internals( p_this )->pp_children[i]; 
    15751574 
    15761575        if( p_tmp->i_object_type == i_type ) 
    1577         { 
    15781576            ListReplace( p_list, p_tmp, p_list->i_count++ ); 
    1579         } 
    1580  
    1581         if( p_tmp->i_children ) 
    1582         { 
    1583             ListChildren( p_list, p_tmp, i_type ); 
    1584         } 
    1585     } 
    1586 
     1577 
     1578        ListChildren( p_list, p_tmp, i_type ); 
     1579    } 
     1580
  • src/modules/cache.c

    r75c438d r8dba805  
    3535#include <stdio.h>                                              /* sprintf() */ 
    3636#include <string.h>                                              /* strdup() */ 
     37#include <vlc_plugin.h> 
    3738 
    3839#ifdef HAVE_SYS_TYPES_H 
     
    563564        SAVE_STRING( pp_cache[i]->p_module->psz_filename ); 
    564565 
    565         i_submodule = pp_cache[i]->p_module->i_children; 
     566        i_submodule = vlc_internals( pp_cache[i]->p_module )->i_children; 
    566567        SAVE_IMMEDIATE( i_submodule ); 
    567568        for( i_submodule = 0; 
    568              i_submodule < (unsigned)pp_cache[i]->p_module->i_children; 
     569             i_submodule < (unsigned)vlc_internals( pp_cache[i]->p_module)->i_children; 
    569570             i_submodule++ ) 
    570571        { 
    571572            module_t *p_module = 
    572                 (module_t *)pp_cache[i]->p_module->pp_children[i_submodule]; 
     573                (module_t *)vlc_internals( pp_cache[i]->p_module )->pp_children[i_submodule]; 
    573574 
    574575            SAVE_STRING( p_module->psz_object_name ); 
     
    687688    p_cache->handle = p_module->handle; 
    688689 
    689     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ ) 
    690     { 
    691         module_t *p_child = (module_t*)p_module->pp_children[i_submodule]; 
    692         module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule]; 
     690    for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ ) 
     691    { 
     692        module_t *p_child = (module_t*)vlc_internals( p_module )->pp_children[i_submodule]; 
     693        module_t *p_cchild = (module_t*)vlc_internals( p_cache )->pp_children[i_submodule]; 
    693694        p_cchild->pf_activate = p_child->pf_activate; 
    694695        p_cchild->pf_deactivate = p_child->pf_deactivate; 
  • src/modules/modules.c

    r48a985e r8dba805  
    215215    vlc_object_detach( p_libvlc_global->p_module_bank ); 
    216216 
    217     while( p_libvlc_global->p_module_bank->i_children ) 
    218     { 
    219         p_next = (module_t *)p_libvlc_global->p_module_bank->pp_children[0]; 
     217    while( vlc_internals( p_libvlc_global->p_module_bank )->i_children ) 
     218    { 
     219        p_next = (module_t *)vlc_internals( p_libvlc_global->p_module_bank )->pp_children[0]; 
    220220        DeleteModule( p_next, true ); 
    221221    } 
     
    12911291                                            : NULL; 
    12921292 
    1293     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ ) 
    1294     { 
    1295         DupModule( (module_t*)p_module->pp_children[ i_submodule ] ); 
     1293    for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ ) 
     1294    { 
     1295        DupModule( (module_t*)vlc_internals( p_module )->pp_children[ i_submodule ] ); 
    12961296    } 
    12971297} 
     
    13071307    int i_submodule; 
    13081308 
    1309     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ ) 
    1310     { 
    1311         UndupModule( (module_t*)p_module->pp_children[ i_submodule ] ); 
     1309    for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ ) 
     1310    { 
     1311        UndupModule( (module_t*)vlc_internals( p_module )->pp_children[ i_submodule ] ); 
    13121312    } 
    13131313 
     
    13941394 
    13951395    /* Free and detach the object's children */ 
    1396     while( p_module->i_children ) 
    1397     { 
    1398         vlc_object_t *p_this = p_module->pp_children[0]; 
     1396    while( vlc_internals( p_module )->i_children ) 
     1397    { 
     1398        vlc_object_t *p_this = vlc_internals( p_module )->pp_children[0]; 
    13991399        vlc_object_detach( p_this ); 
    14001400        vlc_object_release( p_this );