[vlc-devel] commit: Use GCC atomics ( Rémi Denis-Courmont )
git version control
git at videolan.org
Fri Sep 19 16:25:23 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Thu Sep 18 23:24:18 2008 +0300| [d635ae4ed0f1064c07e9209599799c659112f720] | committer: Rémi Denis-Courmont
Use GCC atomics
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d635ae4ed0f1064c07e9209599799c659112f720
---
src/libvlc.c | 28 +++++++++++++++++++++-------
1 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/libvlc.c b/src/libvlc.c
index 87920fb..7e2ae2e 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -118,11 +118,15 @@ void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
{
p_gc->pf_destructor = pf_destruct;
+ p_gc->refs = 1;
+#ifdef __GNUC__
+ __sync_synchronize ();
+#else
/* Nobody else can possibly lock the spin - it's there as a barrier */
vlc_spin_init (&p_gc->spin);
vlc_spin_lock (&p_gc->spin);
- p_gc->refs = 1;
vlc_spin_unlock (&p_gc->spin);
+#endif
return p_gc;
}
@@ -133,12 +137,17 @@ void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
*/
void *vlc_hold (gc_object_t * p_gc)
{
+ uintptr_t refs;
assert( p_gc );
+#ifdef __GNUC__
+ refs = __sync_fetch_and_add (&p_gc->refs, 1);
+#else
vlc_spin_lock (&p_gc->spin);
- assert (p_gc->refs > 0);
- p_gc->refs++;
+ refs = p_gc->refs++;
vlc_spin_unlock (&p_gc->spin);
+#endif
+ assert (refs > 0);
return p_gc;
}
@@ -148,15 +157,20 @@ void *vlc_hold (gc_object_t * p_gc)
*/
void vlc_release (gc_object_t *p_gc)
{
- bool dead;
+ unsigned refs;
assert( p_gc );
+
+#ifdef __GNUC__
+ refs = __sync_fetch_and_sub (&p_gc->refs, 1);
+#else
vlc_spin_lock (&p_gc->spin);
- assert (p_gc->refs > 0);
- dead = !--p_gc->refs;
+ refs = p_gc->refs--;
vlc_spin_unlock (&p_gc->spin);
+#endif
- if (dead)
+ assert (refs > 0);
+ if (refs == 1)
{
vlc_spin_destroy (&p_gc->spin);
p_gc->pf_destructor (p_gc);
More information about the vlc-devel
mailing list