[vlc-commits] stats: vector locking

Rémi Denis-Courmont git at videolan.org
Tue Dec 12 19:36:59 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Dec 12 20:35:08 2017 +0200| [cb46a2200a77858047b76cddf075f7c50d97c5c7] | committer: Rémi Denis-Courmont

stats: vector locking

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

 src/input/access.c         | 10 ----------
 src/input/es_out.c         |  8 ++++----
 src/input/input_internal.h |  6 +++---
 src/input/stats.c          | 24 ++++++++++++++----------
 4 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/src/input/access.c b/src/input/access.c
index 1d4b5ffeef..430f54236c 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -200,13 +200,8 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
     if (block != NULL && input != NULL)
     {
         struct input_stats *stats = input_priv(input)->stats;
-
         if (stats != NULL)
-        {
-            vlc_mutex_lock(&stats->lock);
             input_rate_Add(&stats->input_bitrate, block->i_buffer);
-            vlc_mutex_unlock(&stats->lock);
-        }
     }
 
     return block;
@@ -228,13 +223,8 @@ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
     if (val > 0 && input != NULL)
     {
         struct input_stats *stats = input_priv(input)->stats;
-
         if (stats != NULL)
-        {
-            vlc_mutex_lock(&stats->lock);
             input_rate_Add(&stats->input_bitrate, val);
-            vlc_mutex_unlock(&stats->lock);
-        }
     }
 
     return val;
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 896a2bbb24..787726dc82 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2044,17 +2044,17 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     struct input_stats *stats = input_priv(p_input)->stats;
     if( stats != NULL )
     {
-        vlc_mutex_lock( &stats->lock );
         input_rate_Add( &stats->demux_bitrate, p_block->i_buffer );
 
         /* Update number of corrupted data packats */
         if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
-            stats->demux_corrupted++;
+            atomic_fetch_add_explicit(&stats->demux_corrupted, 1,
+                                      memory_order_relaxed);
 
         /* Update number of discontinuities */
         if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-            stats->demux_discontinuity++;
-        vlc_mutex_unlock( &stats->lock );
+            atomic_fetch_add_explicit(&stats->demux_discontinuity, 1,
+                                      memory_order_relaxed);
     }
 
     vlc_mutex_lock( &p_sys->lock );
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 2803c9f006..16fd662fb3 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -268,6 +268,7 @@ void input_item_node_PostAndDelete( input_item_node_t *p_node );
 /* stats.c */
 typedef struct input_rate_t
 {
+    vlc_mutex_t lock;
     uintmax_t updates;
     uintmax_t value;
     struct
@@ -278,11 +279,10 @@ typedef struct input_rate_t
 } input_rate_t;
 
 struct input_stats {
-    vlc_mutex_t lock;
     input_rate_t input_bitrate;
     input_rate_t demux_bitrate;
-    uintmax_t demux_corrupted;
-    uintmax_t demux_discontinuity;
+    atomic_uintmax_t demux_corrupted;
+    atomic_uintmax_t demux_discontinuity;
     atomic_uintmax_t decoded_audio;
     atomic_uintmax_t decoded_video;
     atomic_uintmax_t played_abuffers;
diff --git a/src/input/stats.c b/src/input/stats.c
index 118cccb67a..3322ea798f 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -36,6 +36,7 @@
  */
 static void input_rate_Init(input_rate_t *rate)
 {
+    vlc_mutex_init(&rate->lock);
     rate->updates = 0;
     rate->value = 0;
     rate->samples[0].date = VLC_TS_INVALID;
@@ -59,38 +60,41 @@ struct input_stats *input_stats_Create(void)
 
     input_rate_Init(&stats->input_bitrate);
     input_rate_Init(&stats->demux_bitrate);
-    stats->demux_corrupted = 0;
-    stats->demux_discontinuity = 0;
+    atomic_init(&stats->demux_corrupted, 0);
+    atomic_init(&stats->demux_discontinuity, 0);
     atomic_init(&stats->decoded_audio, 0);
     atomic_init(&stats->decoded_video, 0);
     atomic_init(&stats->played_abuffers, 0);
     atomic_init(&stats->lost_abuffers, 0);
     atomic_init(&stats->displayed_pictures, 0);
     atomic_init(&stats->lost_pictures, 0);
-    vlc_mutex_init(&stats->lock);
     return stats;
 }
 
 void input_stats_Destroy(struct input_stats *stats)
 {
-    vlc_mutex_destroy(&stats->lock);
+    vlc_mutex_destroy(&stats->demux_bitrate.lock);
+    vlc_mutex_destroy(&stats->input_bitrate.lock);
     free(stats);
 }
 
 void input_stats_Compute(struct input_stats *stats, input_stats_t *st)
 {
-    vlc_mutex_lock(&stats->lock);
-
     /* Input */
+    vlc_mutex_lock(&stats->input_bitrate.lock);
     st->i_read_packets = stats->input_bitrate.updates;
     st->i_read_bytes = stats->input_bitrate.value;
     st->f_input_bitrate = stats_GetRate(&stats->input_bitrate);
+    vlc_mutex_unlock(&stats->input_bitrate.lock);
+
+    vlc_mutex_lock(&stats->demux_bitrate.lock);
     st->i_demux_read_bytes = stats->demux_bitrate.value;
     st->f_demux_bitrate = stats_GetRate(&stats->demux_bitrate);
-    st->i_demux_corrupted = stats->demux_corrupted;
-    st->i_demux_discontinuity = stats->demux_discontinuity;
-
-    vlc_mutex_unlock(&stats->lock);
+    vlc_mutex_unlock(&stats->demux_bitrate.lock);
+    st->i_demux_corrupted = atomic_load_explicit(&stats->demux_corrupted,
+                                                 memory_order_relaxed);
+    st->i_demux_discontinuity = atomic_load_explicit(
+                    &stats->demux_discontinuity, memory_order_relaxed);
 
     /* Aout */
     st->i_decoded_audio = atomic_load_explicit(&stats->decoded_audio,



More information about the vlc-commits mailing list