[vlc-commits] input: count references directly

Rémi Denis-Courmont git at videolan.org
Sun May 13 19:28:06 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 13 19:35:41 2012 +0300| [04146d87f2cf90ebeef7bbac233d83d36aa46f55] | committer: Rémi Denis-Courmont

input: count references directly

The function pointer (in vlc_gc_*) was useless here.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=04146d87f2cf90ebeef7bbac233d83d36aa46f55
---

 src/input/resource.c |   31 ++++++++++++++-----------------
 1 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/input/resource.c b/src/input/resource.c
index 56b729d..3748fbc 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -31,6 +31,7 @@
 #include <assert.h>
 
 #include <vlc_common.h>
+#include <vlc_atomic.h>
 #include <vlc_vout.h>
 #include <vlc_spu.h>
 #include <vlc_aout.h>
@@ -44,7 +45,7 @@
 
 struct input_resource_t
 {
-    VLC_GC_MEMBERS
+    atomic_uint    refs;
 
     vlc_object_t   *p_parent;
 
@@ -420,19 +421,6 @@ static void TerminateAout( input_resource_t *p_resource )
         aout_Destroy( p_aout );
 }
 
-static void Destructor( gc_object_t *p_gc )
-{
-    input_resource_t *p_resource = vlc_priv( p_gc, input_resource_t );
-
-    DestroySout( p_resource );
-    DestroyVout( p_resource );
-    DestroyAout( p_resource );
-
-    vlc_mutex_destroy( &p_resource->lock_hold );
-    vlc_mutex_destroy( &p_resource->lock );
-    free( p_resource );
-}
-
 /* */
 input_resource_t *input_resource_New( vlc_object_t *p_parent )
 {
@@ -440,7 +428,7 @@ input_resource_t *input_resource_New( vlc_object_t *p_parent )
     if( !p_resource )
         return NULL;
 
-    vlc_gc_init( p_resource, Destructor );
+    atomic_init( &p_resource->refs, 1 );
     p_resource->p_parent = p_parent;
     vlc_mutex_init( &p_resource->lock );
     vlc_mutex_init( &p_resource->lock_hold );
@@ -449,12 +437,21 @@ input_resource_t *input_resource_New( vlc_object_t *p_parent )
 
 void input_resource_Release( input_resource_t *p_resource )
 {
-    vlc_gc_decref( p_resource );
+    if( atomic_fetch_sub( &p_resource->refs, 1 ) != 1 )
+        return;
+
+    DestroySout( p_resource );
+    DestroyVout( p_resource );
+    DestroyAout( p_resource );
+
+    vlc_mutex_destroy( &p_resource->lock_hold );
+    vlc_mutex_destroy( &p_resource->lock );
+    free( p_resource );
 }
 
 input_resource_t *input_resource_Hold( input_resource_t *p_resource )
 {
-    vlc_gc_incref( p_resource );
+    atomic_fetch_add( &p_resource->refs, 1 );
     return p_resource;
 }
 



More information about the vlc-commits mailing list