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

picture: socialize the reference counter

parent 442883ab
......@@ -27,6 +27,12 @@
#define VLC_PICTURE_H 1
#include <assert.h>
#ifndef __cplusplus
#include <stdatomic.h>
#else
#include <atomic>
using std::atomic_uintptr_t;
#endif
/**
* \file
......@@ -112,6 +118,8 @@ struct picture_t
/** Next picture in a FIFO a pictures */
struct picture_t *p_next;
atomic_uintptr_t refs;
};
/**
......
......@@ -216,7 +216,7 @@ static picture_priv_t *picture_NewPrivate(const video_format_t *restrict p_fmt,
return NULL;
}
atomic_init( &priv->gc.refs, 1 );
atomic_init(&p_picture->refs, 1);
priv->gc.opaque = NULL;
return priv;
......@@ -324,8 +324,7 @@ picture_t *picture_Hold( picture_t *p_picture )
{
assert( p_picture != NULL );
picture_priv_t *priv = (picture_priv_t *)p_picture;
uintptr_t refs = atomic_fetch_add( &priv->gc.refs, 1 );
uintptr_t refs = atomic_fetch_add(&p_picture->refs, 1);
assert( refs > 0 );
return p_picture;
}
......@@ -335,7 +334,7 @@ void picture_Release( picture_t *p_picture )
assert( p_picture != NULL );
picture_priv_t *priv = (picture_priv_t *)p_picture;
uintptr_t refs = atomic_fetch_sub( &priv->gc.refs, 1 );
uintptr_t refs = atomic_fetch_sub(&p_picture->refs, 1);
assert( refs != 0 );
if( refs > 1 )
return;
......
......@@ -28,7 +28,6 @@ typedef struct
picture_t picture;
struct
{
atomic_uintptr_t refs;
void (*destroy)(picture_t *);
void *opaque;
} gc;
......
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