[vlc-commits] picture: convert to standard atomic operations
Rémi Denis-Courmont
git at videolan.org
Wed Aug 14 19:36:11 CEST 2013
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Aug 14 19:32:05 2013 +0300| [814d530369e6aa5a06c056c23a21d034a7c16565] | committer: Rémi Denis-Courmont
picture: convert to standard atomic operations
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=814d530369e6aa5a06c056c23a21d034a7c16565
---
include/vlc_picture.h | 2 +-
src/misc/picture.c | 17 ++++++++---------
src/misc/picture_pool.c | 21 ++++++++++-----------
3 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 39d50c2..a97f0c5 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -102,7 +102,7 @@ struct picture_t
/** This way the picture_Release can be overloaded */
struct
{
- vlc_atomic_t refcount;
+ atomic_uintptr_t refcount;
void (*pf_destroy)( picture_t * );
picture_gc_sys_t *p_sys;
} gc;
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 017670c1..3e1fb68 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -37,7 +37,6 @@
#include <vlc_picture.h>
#include <vlc_image.h>
#include <vlc_block.h>
-#include <vlc_atomic.h>
/**
* Allocate a new picture in the heap.
@@ -100,7 +99,7 @@ static void PictureDestroyContext( picture_t *p_picture )
static void PictureDestroy( picture_t *p_picture )
{
assert( p_picture &&
- vlc_atomic_get( &p_picture->gc.refcount ) == 0 );
+ atomic_load( &p_picture->gc.refcount ) == 0 );
vlc_free( p_picture->gc.p_sys );
free( p_picture->p_sys );
@@ -141,7 +140,7 @@ int picture_Setup( picture_t *p_picture, vlc_fourcc_t i_chroma,
p->i_pixel_pitch = 0;
}
- vlc_atomic_set( &p_picture->gc.refcount, 0 );
+ atomic_init( &p_picture->gc.refcount, 0 );
p_picture->gc.pf_destroy = NULL;
p_picture->gc.p_sys = NULL;
@@ -248,7 +247,7 @@ picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_r
/* */
p_picture->format = fmt;
- vlc_atomic_set( &p_picture->gc.refcount, 1 );
+ atomic_init( &p_picture->gc.refcount, 1 );
if( p_picture->gc.pf_destroy == NULL )
p_picture->gc.pf_destroy = PictureDestroy;
@@ -277,15 +276,15 @@ picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_
picture_t *picture_Hold( picture_t *p_picture )
{
- vlc_atomic_inc( &p_picture->gc.refcount );
+ atomic_fetch_add( &p_picture->gc.refcount, 1 );
return p_picture;
}
void picture_Release( picture_t *p_picture )
{
- uintptr_t refs = vlc_atomic_dec( &p_picture->gc.refcount );
- assert( refs != (uintptr_t)-1 );
- if( refs > 0 )
+ uintptr_t refs = atomic_fetch_sub( &p_picture->gc.refcount, 1 );
+ assert( refs != 0 );
+ if( refs > 1 )
return;
PictureDestroyContext( p_picture );
@@ -295,7 +294,7 @@ void picture_Release( picture_t *p_picture )
bool picture_IsReferenced( picture_t *p_picture )
{
- return vlc_atomic_get( &p_picture->gc.refcount ) > 1;
+ return atomic_load( &p_picture->gc.refcount ) > 1;
}
/*****************************************************************************
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 14db3b6..af91a7d 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -33,7 +33,6 @@
#include <vlc_common.h>
#include <vlc_picture_pool.h>
-#include <vlc_atomic.h>
/*****************************************************************************
*
@@ -108,7 +107,7 @@ picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg
gc_sys->tick = 0;
/* */
- vlc_atomic_set(&picture->gc.refcount, 0);
+ atomic_init(&picture->gc.refcount, 0);
picture->gc.pf_destroy = Destroy;
picture->gc.p_sys = gc_sys;
@@ -166,7 +165,7 @@ picture_pool_t *picture_pool_Reserve(picture_pool_t *master, int count)
if (master->picture_reserved[i])
continue;
- assert(vlc_atomic_get(&master->picture[i]->gc.refcount) == 0);
+ assert(atomic_load(&master->picture[i]->gc.refcount) == 0);
master->picture_reserved[i] = true;
pool->picture[found] = master->picture[i];
@@ -192,11 +191,11 @@ void picture_pool_Delete(picture_pool_t *pool)
} else {
picture_gc_sys_t *gc_sys = picture->gc.p_sys;
- assert(vlc_atomic_get(&picture->gc.refcount) == 0);
+ assert(atomic_load(&picture->gc.refcount) == 0);
assert(!pool->picture_reserved[i]);
/* Restore old release callback */
- vlc_atomic_set(&picture->gc.refcount, 1);
+ atomic_init(&picture->gc.refcount, 1);
picture->gc.pf_destroy = gc_sys->destroy;
picture->gc.p_sys = gc_sys->destroy_sys;
@@ -217,7 +216,7 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
continue;
picture_t *picture = pool->picture[i];
- if (vlc_atomic_get(&picture->gc.refcount) > 0)
+ if (atomic_load(&picture->gc.refcount) > 0)
continue;
if (Lock(picture))
@@ -242,19 +241,19 @@ void picture_pool_NonEmpty(picture_pool_t *pool, bool reset)
picture_t *picture = pool->picture[i];
if (reset) {
- if (vlc_atomic_get(&picture->gc.refcount) > 0)
+ if (atomic_load(&picture->gc.refcount) > 0)
Unlock(picture);
- vlc_atomic_set(&picture->gc.refcount, 0);
- } else if (vlc_atomic_get(&picture->gc.refcount) == 0) {
+ atomic_store(&picture->gc.refcount, 0);
+ } else if (atomic_load(&picture->gc.refcount) == 0) {
return;
} else if (!old || picture->gc.p_sys->tick < old->gc.p_sys->tick) {
old = picture;
}
}
if (!reset && old) {
- if (vlc_atomic_get(&old->gc.refcount) > 0)
+ if (atomic_load(&old->gc.refcount) > 0)
Unlock(old);
- vlc_atomic_set(&old->gc.refcount, 0);
+ atomic_store(&old->gc.refcount, 0);
}
}
int picture_pool_GetSize(picture_pool_t *pool)
More information about the vlc-commits
mailing list