[vlc-devel] [PATCH 3/4] libvlc: media_list_player: use vlc_atomic_rc for refcount
Alexandre Janniaux
ajanni at videolabs.io
Sat Nov 21 13:21:00 CET 2020
---
lib/media_list_player.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/lib/media_list_player.c b/lib/media_list_player.c
index 2e7405c492..276e825e88 100644
--- a/lib/media_list_player.c
+++ b/lib/media_list_player.c
@@ -36,11 +36,15 @@
#include <vlc/libvlc_events.h>
#include <assert.h>
+#include <vlc_common.h>
+#include <vlc_atomic.h>
+
#include "libvlc_internal.h"
#include "media_internal.h" // Abuse, could and should be removed
#include "media_list_path.h"
+
//#define DEBUG_MEDIA_LIST_PLAYER
/* This is a very dummy implementation of playlist on top of
@@ -58,7 +62,6 @@
struct libvlc_media_list_player_t
{
libvlc_event_manager_t event_manager;
- int i_refcount;
int seek_offset;
bool dead;
/* Protect access to this structure. */
@@ -73,6 +76,7 @@ struct libvlc_media_list_player_t
libvlc_playback_mode_t e_playback_mode;
vlc_thread_t thread;
+ vlc_atomic_rc_t rc;
};
/*
@@ -473,7 +477,7 @@ libvlc_media_list_player_new(libvlc_instance_t * p_instance)
return NULL;
}
- p_mlp->i_refcount = 1;
+ vlc_atomic_rc_init(&p_mlp->rc);
p_mlp->seek_offset = 0;
p_mlp->dead = false;
vlc_mutex_init(&p_mlp->object_lock);
@@ -509,15 +513,8 @@ void libvlc_media_list_player_release(libvlc_media_list_player_t * p_mlp)
if (!p_mlp)
return;
- lock(p_mlp);
- p_mlp->i_refcount--;
- if (p_mlp->i_refcount > 0)
- {
- unlock(p_mlp);
+ if (!vlc_atomic_rc_dec(&p_mlp->rc))
return;
- }
- assert(p_mlp->i_refcount == 0);
- unlock(p_mlp);
vlc_mutex_lock(&p_mlp->mp_callback_lock);
p_mlp->dead = true;
@@ -552,9 +549,7 @@ void libvlc_media_list_player_retain(libvlc_media_list_player_t * p_mlp)
if (!p_mlp)
return;
- lock(p_mlp);
- p_mlp->i_refcount++;
- unlock(p_mlp);
+ vlc_atomic_rc_inc(&p_mlp->rc);
}
/**************************************************************************
--
2.29.2
More information about the vlc-devel
mailing list