[vlc-commits] libvlc: media_player: use vlc_atomic_rc for refcount
Alexandre Janniaux
git at videolan.org
Thu Dec 10 13:39:39 UTC 2020
vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Sat Nov 21 12:45:14 2020 +0100| [6f0f246f315863374c9a0d8d261831909639ddc6] | committer: Alexandre Janniaux
libvlc: media_player: use vlc_atomic_rc for refcount
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6f0f246f315863374c9a0d8d261831909639ddc6
---
lib/media_player.c | 17 +++++------------
lib/media_player_internal.h | 3 +--
2 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/lib/media_player.c b/lib/media_player.c
index b639169835..58dfbc39fb 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -729,7 +729,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
vlc_player_Unlock(mp->player);
- mp->i_refcount = 1;
+ vlc_atomic_rc_init(&mp->rc);
libvlc_event_manager_init(&mp->event_manager, mp);
/* Snapshot initialization */
@@ -824,15 +824,11 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
**************************************************************************/
void libvlc_media_player_release( libvlc_media_player_t *p_mi )
{
- bool destroy;
-
assert( p_mi );
- vlc_player_Lock(p_mi->player);
- destroy = !--p_mi->i_refcount;
- vlc_player_Unlock(p_mi->player);
+ if( !vlc_atomic_rc_dec( &p_mi->rc ) )
+ return;
- if( destroy )
- libvlc_media_player_destroy( p_mi );
+ libvlc_media_player_destroy( p_mi );
}
/**************************************************************************
@@ -843,10 +839,7 @@ void libvlc_media_player_release( libvlc_media_player_t *p_mi )
void libvlc_media_player_retain( libvlc_media_player_t *p_mi )
{
assert( p_mi );
-
- vlc_player_Lock(p_mi->player);
- p_mi->i_refcount++;
- vlc_player_Unlock(p_mi->player);
+ vlc_atomic_rc_inc( &p_mi->rc );
}
/**************************************************************************
diff --git a/lib/media_player_internal.h b/lib/media_player_internal.h
index 1b95fcb355..4a0010e29d 100644
--- a/lib/media_player_internal.h
+++ b/lib/media_player_internal.h
@@ -40,8 +40,7 @@
struct libvlc_media_player_t
{
struct vlc_object_t obj;
-
- int i_refcount;
+ vlc_atomic_rc_t rc;
vlc_player_t *player;
vlc_player_listener_id *listener;
More information about the vlc-commits
mailing list