[vlc-devel] [PATCH 2/7] picture_pool: add private functions to	inc/dec the ref count
    Thomas Guillem 
    thomas at gllm.fr
       
    Wed Jan 11 09:13:09 CET 2017
    
    
  
picture_pool_DecRef() will return true if the pool is destroyed.
---
 src/misc/picture_pool.c | 16 ++++++++++++----
 src/misc/picture_pool.h | 11 +++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 527da051e9..e7b9d34ac2 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -50,21 +50,29 @@ struct picture_pool_t {
     picture_t  *picture[];
 };
 
-static void picture_pool_Destroy(picture_pool_t *pool)
+void picture_pool_IncRef(picture_pool_t *pool)
+{
+    atomic_fetch_add(&pool->refs, 1);
+}
+
+bool picture_pool_DecRef(picture_pool_t *pool)
 {
     if (atomic_fetch_sub(&pool->refs, 1) != 1)
-        return;
+        return false;
+
+    assert(pool->picture_count - popcountll(pool->available) == 0);
 
     vlc_cond_destroy(&pool->wait);
     vlc_mutex_destroy(&pool->lock);
     vlc_free(pool);
+    return true;
 }
 
 void picture_pool_Release(picture_pool_t *pool)
 {
     for (unsigned i = 0; i < pool->picture_count; i++)
         picture_Release(pool->picture[i]);
-    picture_pool_Destroy(pool);
+    picture_pool_DecRef(pool);
 }
 
 static void picture_pool_ReleasePicture(picture_t *clone)
@@ -87,7 +95,7 @@ static void picture_pool_ReleasePicture(picture_t *clone)
     vlc_cond_signal(&pool->wait);
     vlc_mutex_unlock(&pool->lock);
 
-    picture_pool_Destroy(pool);
+    picture_pool_DecRef(pool);
 }
 
 static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
diff --git a/src/misc/picture_pool.h b/src/misc/picture_pool.h
index 35a14e7895..4296970f29 100644
--- a/src/misc/picture_pool.h
+++ b/src/misc/picture_pool.h
@@ -40,3 +40,14 @@ unsigned picture_pool_Reset( picture_pool_t * );
  * picture_pool_Reset will also reset the cancel state to false.
  */
 void picture_pool_Cancel( picture_pool_t *, bool canceled );
+
+/**
+ * Increments the reference count of the pool
+ */
+void picture_pool_IncRef(picture_pool_t *);
+
+/**
+ * Decrements the reference count of the pool
+ * @return true if the pool is destroyed (reference count to 0).
+ */
+bool picture_pool_DecRef(picture_pool_t *);
-- 
2.11.0
    
    
More information about the vlc-devel
mailing list