picture_pool: fix cancellation handling with lock
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 25 Feb 2018 19:06:40 +0000 (21:06 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 25 Feb 2018 19:08:54 +0000 (21:08 +0200)
If there is a deprecated lock callback, the mutex might be released
and the cancellation flag much be rechecked.

Conversely, if the pool is empty, then there is no point in checking
the flag: allocation will anyway fail immediately.

src/misc/picture_pool.c

index e8184e5..fd2724c 100644 (file)
@@ -209,16 +209,13 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
     assert(pool->refs > 0);
     available = pool->available;
 
-    if (pool->canceled)
-    {
-        vlc_mutex_unlock(&pool->lock);
-        return NULL;
-    }
-
     while (available != 0)
     {
         int i = ctz(available);
 
+        if (unlikely(pool->canceled))
+            break;
+
         pool->available &= ~(1ULL << i);
         vlc_mutex_unlock(&pool->lock);
         available &= ~(1ULL << i);