[vlc-devel] [PATCH 1/2] picture_pool: move code
Thomas Guillem
thomas at gllm.fr
Fri Dec 30 17:58:20 CET 2016
No functional changes. Move up picture_pool_Get and rename it to
picture_pool_GetInternal. This new function will be used by the following
commit.
---
src/misc/picture_pool.c | 89 ++++++++++++++++++++++++++-----------------------
1 file changed, 48 insertions(+), 41 deletions(-)
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 8a507acb55..875aff42ab 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -113,6 +113,52 @@ static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
return clone;
}
+/** Find next (bit) set */
+static int fnsll(unsigned long long x, unsigned i)
+{
+ if (i >= CHAR_BIT * sizeof (x))
+ return 0;
+ return ffsll(x & ~((1ULL << i) - 1));
+}
+
+static picture_t *picture_pool_GetInternal(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));
+ vlc_mutex_unlock(&pool->lock);
+
+ picture_t *picture = pool->picture[i - 1];
+
+ if (pool->pic_lock != NULL
+ && pool->pic_lock(picture) != VLC_SUCCESS)
+ {
+ vlc_mutex_lock(&pool->lock);
+ pool->available |= 1ULL << (i - 1);
+ continue;
+ }
+
+ picture_t *clone = picture_pool_ClonePicture(pool, i - 1);
+ if (clone != NULL) {
+ assert(clone->p_next == NULL);
+ atomic_fetch_add(&pool->refs, 1);
+ }
+ return clone;
+ }
+
+ vlc_mutex_unlock(&pool->lock);
+ return NULL;
+}
+
picture_pool_t *picture_pool_NewExtended(const picture_pool_configuration_t *cfg)
{
if (unlikely(cfg->picture_count > pool_max))
@@ -176,7 +222,7 @@ picture_pool_t *picture_pool_Reserve(picture_pool_t *master, unsigned count)
unsigned i;
for (i = 0; i < count; i++) {
- picture[i] = picture_pool_Get(master);
+ picture[i] = picture_pool_GetInternal(master);
if (picture[i] == NULL)
goto error;
}
@@ -193,48 +239,9 @@ error:
return NULL;
}
-/** Find next (bit) set */
-static int fnsll(unsigned long long x, unsigned i)
-{
- if (i >= CHAR_BIT * sizeof (x))
- return 0;
- return ffsll(x & ~((1ULL << i) - 1));
-}
-
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));
- vlc_mutex_unlock(&pool->lock);
-
- picture_t *picture = pool->picture[i - 1];
-
- if (pool->pic_lock != NULL && pool->pic_lock(picture) != VLC_SUCCESS) {
- vlc_mutex_lock(&pool->lock);
- pool->available |= 1ULL << (i - 1);
- continue;
- }
-
- picture_t *clone = picture_pool_ClonePicture(pool, i - 1);
- if (clone != NULL) {
- assert(clone->p_next == NULL);
- atomic_fetch_add(&pool->refs, 1);
- }
- return clone;
- }
-
- vlc_mutex_unlock(&pool->lock);
- return NULL;
+ return picture_pool_GetInternal(pool);
}
picture_t *picture_pool_Wait(picture_pool_t *pool)
--
2.11.0
More information about the vlc-devel
mailing list