Changeset 070e3454880e849f3ebca21d5f803cdd13351049

Show
Ignore:
Timestamp:
31/05/08 22:51:19 (6 months ago)
Author:
Rémi Denis-Courmont <rdenis@simphalempin.com>
git-committer:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1212267079 +0300
git-parent:

[90fd835fb4e43fcc2cb0b80d988b253843c4c548]

git-author:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1212267079 +0300
Message:

Keep track of object held by threads

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/misc/objects.c

    r90fd835 r070e345  
    33 ***************************************************************************** 
    44 * Copyright (C) 2004-2008 the VideoLAN team 
    5  * $Id$ 
    65 * 
    76 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    8281static void vlc_object_destroy( vlc_object_t *p_this ); 
    8382static void vlc_object_detach_unlocked (vlc_object_t *p_this); 
     83 
     84#ifndef NDEBUG 
     85static vlc_threadvar_t held_objects; 
     86typedef struct held_list_t 
     87{ 
     88    struct held_list_t *next; 
     89    vlc_object_t *obj; 
     90} held_list_t; 
     91#endif 
    8492 
    8593/***************************************************************************** 
     
    143151        p_priv->next = p_priv->prev = p_new; 
    144152        vlc_mutex_init( &structure_lock ); 
     153#ifndef NDEBUG 
     154        /* TODO: use the destruction callback to track ref leaks */ 
     155        vlc_threadvar_create( &held_objects, NULL ); 
     156#endif 
    145157    } 
    146158    else 
     
    372384        /* We are the global object ... no need to lock. */ 
    373385        vlc_mutex_destroy( &structure_lock ); 
     386#ifndef NDEBUG 
     387        vlc_threadvar_delete( &held_objects ); 
     388#endif 
    374389    } 
    375390 
     
    779794    internals->i_refcount++; 
    780795    vlc_spin_unlock( &internals->ref_spin ); 
     796#ifndef NDEBUG 
     797    /* Update the list of referenced objects */ 
     798    /* Using TLS, so no need to lock */ 
     799    held_list_t *newhead = malloc (sizeof (*newhead)); 
     800    held_list_t *oldhead = vlc_threadvar_get (&held_objects); 
     801    newhead->next = oldhead; 
     802    newhead->obj = p_this; 
     803    vlc_threadvar_set (&held_objects, newhead); 
     804#endif 
    781805} 
    782806 
     
    789813    vlc_object_internals_t *internals = vlc_internals( p_this ); 
    790814    bool b_should_destroy; 
     815 
     816#ifndef NDEBUG 
     817    /* Update the list of referenced objects */ 
     818    /* Using TLS, so no need to lock */ 
     819    for (held_list_t *hlcur = vlc_threadvar_get (&held_objects), 
     820                     *hlprev = NULL; 
     821         hlcur != NULL; 
     822         hlcur = hlcur->next) 
     823    { 
     824        if (hlcur->obj == p_this) 
     825        { 
     826            if (hlprev == NULL) 
     827                vlc_threadvar_set (&held_objects, hlcur->next); 
     828            else 
     829                hlprev->next = hlcur->next; 
     830            free (hlcur); 
     831            break; 
     832        } 
     833    } 
     834    /* TODO: what if releasing without references? */ 
     835#endif 
    791836 
    792837    vlc_spin_lock( &internals->ref_spin );