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 @@
*****************************************************************************/
#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
......@@ -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;
}
......
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