[vlc-commits] vout: use atomic variables for stats instead of spin lock
Rémi Denis-Courmont
git at videolan.org
Thu Nov 8 23:36:46 CET 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Nov 9 00:36:33 2012 +0200| [a5e3a954b54587db0a7b47320f94ed7284122763] | committer: Rémi Denis-Courmont
vout: use atomic variables for stats instead of spin lock
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a5e3a954b54587db0a7b47320f94ed7284122763
---
src/video_output/statistic.h | 40 +++++++++++++++++++++------------------
src/video_output/video_output.c | 4 ++--
2 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/src/video_output/statistic.h b/src/video_output/statistic.h
index e17386e..083b0d7 100644
--- a/src/video_output/statistic.h
+++ b/src/video_output/statistic.h
@@ -22,39 +22,43 @@
*****************************************************************************/
#ifndef LIBVLC_VOUT_STATISTIC_H
-#define LIBVLC_VOUT_STATISTIC_H
+# define LIBVLC_VOUT_STATISTIC_H
+# include <vlc_atomic.h>
+/* NOTE: Both statistics are atomic on their own, so one might be older than
+ * the other one. Currently, only one of them is updated at a time, so this
+ * is a non-issue. */
typedef struct {
- vlc_spinlock_t spin;
-
- int displayed;
- int lost;
+ atomic_uint displayed;
+ atomic_uint lost;
} vout_statistic_t;
static inline void vout_statistic_Init(vout_statistic_t *stat)
{
- vlc_spin_init(&stat->spin);
+ atomic_init(&stat->displayed, 0);
+ atomic_init(&stat->lost, 0);
}
+
static inline void vout_statistic_Clean(vout_statistic_t *stat)
{
- vlc_spin_destroy(&stat->spin);
+ (void) stat;
}
+
static inline void vout_statistic_GetReset(vout_statistic_t *stat, int *displayed, int *lost)
{
- vlc_spin_lock(&stat->spin);
- *displayed = stat->displayed;
- *lost = stat->lost;
+ *displayed = atomic_exchange(&stat->displayed, 0);
+ *lost = atomic_exchange(&stat->lost, 0);
+}
- stat->displayed = 0;
- stat->lost = 0;
- vlc_spin_unlock(&stat->spin);
+static inline void vout_statistic_AddDisplayed(vout_statistic_t *stat,
+ int displayed)
+{
+ atomic_fetch_add(&stat->displayed, displayed);
}
-static inline void vout_statistic_Update(vout_statistic_t *stat, int displayed, int lost)
+
+static inline void vout_statistic_AddLost(vout_statistic_t *stat, int lost)
{
- vlc_spin_lock(&stat->spin);
- stat->displayed += displayed;
- stat->lost += lost;
- vlc_spin_unlock(&stat->spin);
+ atomic_fetch_add(&stat->lost, lost);
}
#endif
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 0a68cc8..b83d040 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -862,7 +862,7 @@ static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool is_
vlc_mutex_unlock(&vout->p->filter.lock);
- vout_statistic_Update(&vout->p->statistic, 0, lost_count);
+ vout_statistic_AddLost(&vout->p->statistic, lost_count);
if (!picture)
return VLC_EGENERIC;
@@ -1056,7 +1056,7 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
subpic);
sys->display.filtered = NULL;
- vout_statistic_Update(&vout->p->statistic, 1, 0);
+ vout_statistic_AddDisplayed(&vout->p->statistic, 1);
return VLC_SUCCESS;
}
More information about the vlc-commits
mailing list