Commit a5e3a954 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

vout: use atomic variables for stats instead of spin lock

parent 9b925e51
...@@ -22,39 +22,43 @@ ...@@ -22,39 +22,43 @@
*****************************************************************************/ *****************************************************************************/
#ifndef LIBVLC_VOUT_STATISTIC_H #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 { typedef struct {
vlc_spinlock_t spin; atomic_uint displayed;
atomic_uint lost;
int displayed;
int lost;
} vout_statistic_t; } vout_statistic_t;
static inline void vout_statistic_Init(vout_statistic_t *stat) 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) 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) static inline void vout_statistic_GetReset(vout_statistic_t *stat, int *displayed, int *lost)
{ {
vlc_spin_lock(&stat->spin); *displayed = atomic_exchange(&stat->displayed, 0);
*displayed = stat->displayed; *lost = atomic_exchange(&stat->lost, 0);
*lost = stat->lost; }
stat->displayed = 0; static inline void vout_statistic_AddDisplayed(vout_statistic_t *stat,
stat->lost = 0; int displayed)
vlc_spin_unlock(&stat->spin); {
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); atomic_fetch_add(&stat->lost, lost);
stat->displayed += displayed;
stat->lost += lost;
vlc_spin_unlock(&stat->spin);
} }
#endif #endif
...@@ -862,7 +862,7 @@ static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool is_ ...@@ -862,7 +862,7 @@ static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool is_
vlc_mutex_unlock(&vout->p->filter.lock); 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) if (!picture)
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -1056,7 +1056,7 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced) ...@@ -1056,7 +1056,7 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
subpic); subpic);
sys->display.filtered = NULL; sys->display.filtered = NULL;
vout_statistic_Update(&vout->p->statistic, 1, 0); vout_statistic_AddDisplayed(&vout->p->statistic, 1);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment