Commit e4752428 authored by Thomas Guillem's avatar Thomas Guillem Committed by Rémi Denis-Courmont

picture_pool: add picture_pool_Cancel

Signed-off-by: Rémi Denis-Courmont's avatarRémi Denis-Courmont <remi@remlab.net>
parent c41a4a3e
......@@ -157,6 +157,15 @@ VLC_API void picture_pool_Enum( picture_pool_t *,
*/
unsigned picture_pool_Reset( picture_pool_t * );
/**
* Cancel the picture pool.
*
* It won't return any pictures via picture_pool_Get or picture_pool_Wait after
* this call. This function will also unblock picture_pool_Wait. Call
* picture_pool_Reset to reset the cancel state.
*/
void picture_pool_Cancel( picture_pool_t * );
/**
* Reserves pictures from a pool and creates a new pool with those.
*
......
......@@ -42,6 +42,7 @@ struct picture_pool_t {
vlc_mutex_t lock;
vlc_cond_t wait;
bool canceled;
unsigned long long available;
atomic_ushort refs;
unsigned short picture_count;
......@@ -131,6 +132,7 @@ picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg
pool->picture_count = cfg->picture_count;
memcpy(pool->picture, cfg->picture,
cfg->picture_count * sizeof (picture_t *));
pool->canceled = false;
return pool;
}
......@@ -204,6 +206,12 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
vlc_mutex_lock(&pool->lock);
assert(pool->refs > 0);
if (pool->canceled)
{
vlc_mutex_unlock(&pool->lock);
return NULL;
}
for (unsigned i = ffsll(pool->available); i; i = fnsll(pool->available, i))
{
pool->available &= ~(1ULL << (i - 1));
......@@ -236,9 +244,15 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
vlc_mutex_lock(&pool->lock);
assert(pool->refs > 0);
while (pool->available == 0)
while (pool->available == 0 && !pool->canceled)
vlc_cond_wait(&pool->wait, &pool->lock);
if (pool->canceled)
{
vlc_mutex_unlock(&pool->lock);
return NULL;
}
i = ffsll(pool->available);
assert(i > 0);
pool->available &= ~(1ULL << (i - 1));
......@@ -262,6 +276,16 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
return clone;
}
void picture_pool_Cancel(picture_pool_t *pool)
{
vlc_mutex_lock(&pool->lock);
assert(pool->refs > 0);
pool->canceled = true;
vlc_cond_signal(&pool->wait);
vlc_mutex_unlock(&pool->lock);
}
unsigned picture_pool_Reset(picture_pool_t *pool)
{
unsigned ret;
......@@ -270,6 +294,7 @@ unsigned picture_pool_Reset(picture_pool_t *pool)
assert(pool->refs > 0);
ret = pool->picture_count - popcountll(pool->available);
pool->available = (1ULL << pool->picture_count) - 1;
pool->canceled = false;
vlc_mutex_unlock(&pool->lock);
return ret;
......
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