[vlc-commits] input: private input item reference count
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 20:03:28 2012 +0300| [da623e255826e2add28d2709545b523f911f5b1b] | committer: Rémi Denis-Courmont
input: private input item reference count
(And remove an useless constant function pointer.)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=da623e255826e2add28d2709545b523f911f5b1b
---
include/vlc_input_item.h | 10 +++++++++-
src/input/item.c | 21 +++++++++++++++------
src/input/item.h | 2 ++
src/libvlccore.sym | 2 ++
4 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 6869572..2f74077 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -54,7 +54,6 @@ struct info_category_t
struct input_item_t
{
- VLC_GC_MEMBERS
int i_id; /**< Identifier of the item */
char *psz_name; /**< text describing this item */
@@ -267,6 +266,15 @@ VLC_API input_item_t * input_item_NewExt( const char *psz_uri, const char *psz_n
*/
VLC_API input_item_t * input_item_Copy(input_item_t * ) VLC_USED;
+/** Holds an input item, i.e. creates a new reference. */
+VLC_API input_item_t *input_item_Hold(input_item_t *);
+
+/** Releases an input item, i.e. decrements its reference counter. */
+VLC_API void input_item_Release(input_item_t *);
+
+/* Historical hack... */
+#define vlc_gc_incref(i) input_item_Hold(i)
+#define vlc_gc_decref(i) input_item_Release(i)
/******************
* Input stats
diff --git a/src/input/item.c b/src/input/item.c
index dff81ba..d1e4abf 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -29,10 +29,8 @@
#include <vlc_common.h>
#include <vlc_url.h>
-#include "vlc_playlist.h"
-#include "vlc_interface.h"
+#include <vlc_interface.h>
#include <vlc_charset.h>
-#include <vlc_atomic.h>
#include "item.h"
#include "info.h"
@@ -407,11 +405,21 @@ bool input_item_IsArtFetched( input_item_t *p_item )
return b_fetched;
}
-static void input_item_Destroy ( gc_object_t *p_gc )
+input_item_t *input_item_Hold( input_item_t *p_item )
{
- input_item_t *p_item = vlc_priv( p_gc, input_item_t );
input_item_owner_t *owner = item_owner(p_item);
+ atomic_fetch_add( &owner->refs, 1 );
+ return p_item;
+}
+
+void input_item_Release( input_item_t *p_item )
+{
+ input_item_owner_t *owner = item_owner(p_item);
+
+ if( atomic_fetch_sub(&owner->refs, 1) != 1 )
+ return;
+
vlc_event_manager_fini( &p_item->event_manager );
free( p_item->psz_name );
@@ -810,11 +818,12 @@ input_item_NewWithType( const char *psz_uri, const char *psz_name,
if( unlikely(owner == NULL) )
return NULL;
+ atomic_init( &owner->refs, 1 );
+
input_item_t *p_input = &owner->item;
vlc_event_manager_t * p_em = &p_input->event_manager;
p_input->i_id = atomic_fetch_add(&last_input_id, 1);
- vlc_gc_init( p_input, input_item_Destroy );
vlc_mutex_init( &p_input->lock );
p_input->psz_name = NULL;
diff --git a/src/input/item.h b/src/input/item.h
index c4542ae..aa31d05 100644
--- a/src/input/item.h
+++ b/src/input/item.h
@@ -25,6 +25,7 @@
#define LIBVLC_INPUT_ITEM_H 1
#include "input_interface.h"
+#include <vlc_atomic.h>
void input_item_SetErrorWhenReading( input_item_t *p_i, bool b_error );
void input_item_UpdateTracksInfo( input_item_t *item, const es_format_t *fmt );
@@ -32,6 +33,7 @@ void input_item_UpdateTracksInfo( input_item_t *item, const es_format_t *fmt );
typedef struct input_item_owner
{
input_item_t item;
+ atomic_uint refs;
} input_item_owner_t;
# define item_owner(item) ((struct input_item_owner *)(item))
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 921e513..a281554 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -197,6 +197,8 @@ input_item_MetaMatch
input_item_MergeInfos
input_item_NewExt
input_item_NewWithType
+input_item_Hold
+input_item_Release
input_item_node_AppendItem
input_item_node_AppendNode
input_item_node_Create
More information about the vlc-commits
mailing list