[vlc-commits] picture_pool: simplify using ctz()

Rémi Denis-Courmont git at videolan.org
Sun Feb 25 20:21:26 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 25 21:05:19 2018 +0200| [f8e00adcdc96457cb4b1bf36f9378db773736224] | committer: Rémi Denis-Courmont

picture_pool: simplify using ctz()

Same as 09fa628168421b5d8881b72ced9390d84dd58123.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f8e00adcdc96457cb4b1bf36f9378db773736224
---

 src/misc/picture_pool.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index fd2724cc18..74712c81f5 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -242,8 +242,6 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
 
 picture_t *picture_pool_Wait(picture_pool_t *pool)
 {
-    unsigned i;
-
     vlc_mutex_lock(&pool->lock);
     assert(pool->refs > 0);
 
@@ -257,22 +255,21 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)
         vlc_cond_wait(&pool->wait, &pool->lock);
     }
 
-    i = ffsll(pool->available);
-    assert(i > 0);
-    pool->available &= ~(1ULL << (i - 1));
+    int i = ctz(pool->available);
+    pool->available &= ~(1ULL << i);
     vlc_mutex_unlock(&pool->lock);
 
-    picture_t *picture = pool->picture[i - 1];
+    picture_t *picture = pool->picture[i];
 
     if (pool->pic_lock != NULL && pool->pic_lock(picture) != VLC_SUCCESS) {
         vlc_mutex_lock(&pool->lock);
-        pool->available |= 1ULL << (i - 1);
+        pool->available |= 1ULL << i;
         vlc_cond_signal(&pool->wait);
         vlc_mutex_unlock(&pool->lock);
         return NULL;
     }
 
-    picture_t *clone = picture_pool_ClonePicture(pool, i - 1);
+    picture_t *clone = picture_pool_ClonePicture(pool, i);
     if (clone != NULL) {
         assert(clone->p_next == NULL);
         atomic_fetch_add(&pool->refs, 1);



More information about the vlc-commits mailing list