[vlc-commits] picture_pool: add picture_pool_Cancel

Thomas Guillem git at videolan.org
Mon Nov 30 19:17:26 CET 2015


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Nov 18 14:31:59 2015 +0100| [e47524287478bc102809248904b2aa4dad67511e] | committer: Rémi Denis-Courmont

picture_pool: add picture_pool_Cancel

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

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

 include/vlc_picture_pool.h |    9 +++++++++
 src/misc/picture_pool.c    |   27 ++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/vlc_picture_pool.h b/include/vlc_picture_pool.h
index ec4bf39..d967955 100644
--- a/include/vlc_picture_pool.h
+++ b/include/vlc_picture_pool.h
@@ -158,6 +158,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.
  *
  * When the new pool is released, pictures are returned to the master pool.
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index f82cb16..ececf19 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -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;



More information about the vlc-commits mailing list