Changeset 523ef308d2bff928d1246e968003a3ff429890db

Show
Ignore:
Timestamp:
28/05/08 21:32:25 (4 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1212003145 +0300
git-parent:

[1746fdda5a2bc062d52a3b8a30d9d1d6518e64b4]

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

The totally dumb reference checker

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/libvlc.h

    r1746fdd r523ef30  
    4747void vlc_threads_end( void ); 
    4848vlc_object_t *vlc_threadobj (void); 
     49#ifndef NDEBUG 
     50void vlc_refcheck (vlc_object_t *obj); 
     51#else 
     52# define vlc_refcheck( obj ) (void)0 
     53#endif 
    4954 
    5055/* 
  • src/misc/objects.c

    r1746fdd r523ef30  
    14701470    } 
    14711471} 
     1472 
     1473#ifndef NDEBUG 
     1474void vlc_refcheck (vlc_object_t *obj) 
     1475{ 
     1476    static unsigned errors = 0; 
     1477    vlc_object_t *caller = vlc_threadobj (); 
     1478    vlc_object_internals_t *priv = vlc_internals (obj); 
     1479    int refs; 
     1480 
     1481    if (errors > 100) 
     1482        return; 
     1483 
     1484    if (!caller) 
     1485        return; /* main thread, not sure how to handle it */ 
     1486 
     1487    /* An object can always access itself without reference! */ 
     1488    if (caller == obj) 
     1489        return; 
     1490 
     1491    /* The calling thread is younger than the object. 
     1492     * Access could be valid, we would need more accounting. */ 
     1493    if (caller->i_object_id > obj->i_object_id) 
     1494        return; 
     1495 
     1496    vlc_spin_lock (&priv->ref_spin); 
     1497    refs = priv->i_refcount; 
     1498    vlc_spin_unlock (&priv->ref_spin); 
     1499 
     1500    /* Object has more than one reference. 
     1501     * The current thread could be holding a valid reference. */ 
     1502    if (refs > 1) 
     1503        return; 
     1504 
     1505    /* The parent of an object normally holds the unique reference. 
     1506     * As not all objects are threads, it could also be an ancestor. */ 
     1507    vlc_mutex_lock (&structure_lock); 
     1508    for (vlc_object_t *cur = obj; cur != NULL; cur = cur->p_parent) 
     1509        if (cur == caller) 
     1510        { 
     1511            vlc_mutex_unlock (&structure_lock); 
     1512            return; 
     1513        } 
     1514    vlc_mutex_unlock (&structure_lock); 
     1515 
     1516#if 1 
     1517    if (caller->i_object_type == VLC_OBJECT_PLAYLIST) 
     1518        return; /* Playlist is too clever, or hopelessly broken. */ 
     1519#endif 
     1520    msg_Err (caller, "This thread is accessing..."); 
     1521    msg_Err (obj, "...this object in a suspicious manner."); 
     1522 
     1523    if (++errors == 100) 
     1524        msg_Err (caller, "Too many reference errors"); 
     1525} 
     1526#endif 
  • src/misc/variables.c

    r2f601f6 r523ef30  
    169169    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    170170 
     171    vlc_refcheck( p_this ); 
    171172    vlc_mutex_lock( &p_priv->var_lock ); 
    172173 
     
    332333    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    333334 
     335    vlc_refcheck( p_this ); 
    334336    vlc_mutex_lock( &p_priv->var_lock ); 
    335337 
     
    408410    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    409411 
     412    vlc_refcheck( p_this ); 
    410413    vlc_mutex_lock( &p_priv->var_lock ); 
    411414 
     
    760763    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    761764 
     765    vlc_refcheck( p_this ); 
    762766    vlc_mutex_lock( &p_priv->var_lock ); 
    763767 
     
    837841    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    838842 
     843    vlc_refcheck( p_this ); 
    839844    vlc_mutex_lock( &p_priv->var_lock ); 
    840845 
     
    903908    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    904909 
     910    vlc_refcheck( p_this ); 
    905911    entry.pf_callback = pf_callback; 
    906912    entry.p_data = p_data; 
     
    940946    vlc_object_internals_t *p_priv = vlc_internals( p_this ); 
    941947 
     948    vlc_refcheck( p_this ); 
    942949    vlc_mutex_lock( &p_priv->var_lock ); 
    943950 
     
    15761583    } 
    15771584 
     1585    vlc_refcheck( p_this ); 
    15781586    i_type = var_Type( p_obj, psz_cmd ); 
    15791587    if( !( i_type&VLC_VAR_ISCOMMAND ) )