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

picture_pool: release unused pictures immediately

When the pool is released, the pictures were destroyed only once all
references to all pooled pictures were released. Now, each picture is
destroyed individually when it is no longer referenced.
parent 0be2aad8
...@@ -46,7 +46,7 @@ struct picture_pool_t { ...@@ -46,7 +46,7 @@ struct picture_pool_t {
picture_t *picture[]; picture_t *picture[];
}; };
void picture_pool_Release(picture_pool_t *pool) static void picture_pool_Destroy(picture_pool_t *pool)
{ {
bool destroy; bool destroy;
...@@ -58,31 +58,37 @@ void picture_pool_Release(picture_pool_t *pool) ...@@ -58,31 +58,37 @@ void picture_pool_Release(picture_pool_t *pool)
if (likely(!destroy)) if (likely(!destroy))
return; return;
for (unsigned i = 0; i < pool->picture_count; i++)
picture_Release(pool->picture[i]);
vlc_mutex_destroy(&pool->lock); vlc_mutex_destroy(&pool->lock);
vlc_free(pool); vlc_free(pool);
} }
static void picture_pool_ReleasePicture(picture_t *picture) void picture_pool_Release(picture_pool_t *pool)
{ {
picture_priv_t *priv = (picture_priv_t *)picture; for (unsigned i = 0; i < pool->picture_count; i++)
picture_Release(pool->picture[i]);
picture_pool_Destroy(pool);
}
static void picture_pool_ReleasePicture(picture_t *clone)
{
picture_priv_t *priv = (picture_priv_t *)clone;
uintptr_t sys = (uintptr_t)priv->gc.opaque; uintptr_t sys = (uintptr_t)priv->gc.opaque;
picture_pool_t *pool = (void *)(sys & ~(pool_max - 1)); picture_pool_t *pool = (void *)(sys & ~(pool_max - 1));
unsigned offset = sys & (pool_max - 1); unsigned offset = sys & (pool_max - 1);
picture_t *picture = pool->picture[offset];
free(clone);
if (pool->pic_unlock != NULL) if (pool->pic_unlock != NULL)
pool->pic_unlock(pool->picture[offset]); pool->pic_unlock(picture);
picture_Release(picture);
vlc_mutex_lock(&pool->lock); vlc_mutex_lock(&pool->lock);
assert(!(pool->available & (1ULL << offset))); assert(!(pool->available & (1ULL << offset)));
pool->available |= 1ULL << offset; pool->available |= 1ULL << offset;
vlc_mutex_unlock(&pool->lock); vlc_mutex_unlock(&pool->lock);
picture_pool_Release(pool); picture_pool_Destroy(pool);
free(picture);
} }
static picture_t *picture_pool_ClonePicture(picture_pool_t *pool, static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
...@@ -102,8 +108,10 @@ static picture_t *picture_pool_ClonePicture(picture_pool_t *pool, ...@@ -102,8 +108,10 @@ static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
} }
picture_t *clone = picture_NewFromResource(&picture->format, &res); picture_t *clone = picture_NewFromResource(&picture->format, &res);
if (likely(clone != NULL)) if (likely(clone != NULL)) {
((picture_priv_t *)clone)->gc.opaque = (void *)sys; ((picture_priv_t *)clone)->gc.opaque = (void *)sys;
picture_Hold(picture);
}
return clone; return clone;
} }
...@@ -126,7 +134,6 @@ picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg ...@@ -126,7 +134,6 @@ picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg
memcpy(pool->picture, cfg->picture, memcpy(pool->picture, cfg->picture,
cfg->picture_count * sizeof (picture_t *)); cfg->picture_count * sizeof (picture_t *));
return pool; return pool;
} }
picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab) picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab)
......
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