[vlc-commits] aout: use atomic variable instead of aout lock for statistics

Rémi Denis-Courmont git at videolan.org
Sun Nov 11 16:07:12 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 11 17:06:46 2012 +0200| [04c94d3708e7662c2c683997145b1d6ceb9c96f2] | committer: Rémi Denis-Courmont

aout: use atomic variable instead of aout lock for statistics

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

 src/audio_output/aout_internal.h |    3 +--
 src/audio_output/dec.c           |   17 +++++------------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 994ffac..d9a8706 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -75,8 +75,7 @@ typedef struct
     aout_request_vout_t request_vout;
     bool recycle_vout;
 
-    unsigned buffers_lost;
-
+    atomic_uint buffers_lost;
     vlc_atomic_t restart;
 } aout_owner_t;
 
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index bbf48cc..54fa306 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -96,10 +96,10 @@ error:
     date_Init (&owner->sync.date, owner->mixer_format.i_rate, 1);
     date_Set (&owner->sync.date, VLC_TS_INVALID);
     owner->sync.resamp_type = AOUT_RESAMPLING_NONE;
+    aout_unlock( p_aout );
 
-    owner->buffers_lost = 0;
+    atomic_init (&owner->buffers_lost, 0);
 
-    aout_unlock( p_aout );
     return ret;
 }
 
@@ -317,7 +317,7 @@ int aout_DecPlay (audio_output_t *aout, block_t *block, int input_rate)
     block = aout_FiltersPlay (aout, block, input_rate);
     if (block == NULL)
     {
-        owner->buffers_lost++;
+        atomic_fetch_add(&owner->buffers_lost, 1);
         goto out;
     }
 
@@ -386,21 +386,14 @@ out:
     return 0;
 drop:
     block_Release (block);
-    owner->buffers_lost++;
+    atomic_fetch_add(&owner->buffers_lost, 1);
     goto out;
 }
 
 int aout_DecGetResetLost (audio_output_t *aout)
 {
     aout_owner_t *owner = aout_owner (aout);
-    unsigned val;
-
-    aout_lock (aout);
-    val = owner->buffers_lost;
-    owner->buffers_lost = 0;
-    aout_unlock (aout);
-
-    return val;
+    return atomic_exchange(&owner->buffers_lost, 0);
 }
 
 void aout_DecChangePause (audio_output_t *aout, bool paused, mtime_t date)



More information about the vlc-commits mailing list