<html><head></head><body>Hi,<br><br>I don't really see the point in splitting this to a separate structure seen as it's impossible to disentangle the internals.<br><br><div class="gmail_quote">Le 27 juillet 2020 16:45:23 GMT+03:00, Steve Lhomme <robux4@ycbcr.xyz> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail"><hr> include/vlc_picture_pool.h | 27 ++++++++++++++++<br> src/misc/picture_pool.c | 66 ++++++++++++++++++++++++--------------<br> 2 files changed, 69 insertions(+), 24 deletions(-)<br><br>diff --git a/include/vlc_picture_pool.h b/include/vlc_picture_pool.h<br>index 4f4010f745a..70617aa660a 100644<br>--- a/include/vlc_picture_pool.h<br>+++ b/include/vlc_picture_pool.h<br>@@ -30,6 +30,8 @@<br> <br> #include <vlc_picture.h><br> <br>+typedef struct vlc_cancelable vlc_cancelable;<br>+<br> /**<br> * Picture pool handle<br> */<br>@@ -137,5 +139,30 @@ VLC_USED;<br> unsigned picture_pool_GetSize(const picture_pool_t *);<br> <br> <br>+struct vlc_cancelable {<br>+ vlc_mutex_t lock;<br>+ vlc_cond_t wait;<br>+ bool canceled;<br>+};<br>+<br>+/**<br>+ * Initialize a vlc_cancelable<br>+ */<br>+void vlc_cancelable_Init(vlc_cancelable *);<br>+<br>+/**<br>+ * Wait for until the vlc_cancelable is canceled or it's signaled.<br>+ */<br>+bool vlc_cancelable_Wait(vlc_cancelable*);<br>+<br>+/**<br>+ * Set the canceled state of the vlc_cancelable.<br>+ *<br>+ * This function will also unblock vlc_cancelable_Wait() if the vlc_cancelable<br>+ * is set to canceled.<br>+ */<br>+void vlc_cancelable_SetCanceled(vlc_cancelable*, bool);<br>+<br>+<br> #endif /* VLC_PICTURE_POOL_H */<br> <br>diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c<br>index a942a697995..2605b37454f 100644<br>--- a/src/misc/picture_pool.c<br>+++ b/src/misc/picture_pool.c<br>@@ -39,10 +39,8 @@<br> static_assert ((POOL_MAX & (POOL_MAX - 1)) == 0, "Not a power of two");<br> <br> struct picture_pool_t {<br>- vlc_mutex_t lock;<br>- vlc_cond_t wait;<br>+ vlc_cancelable cancel;<br> <br>- bool canceled;<br> unsigned long long available;<br> atomic_ushort refs;<br> unsigned short picture_count;<br>@@ -75,11 +73,11 @@ static void picture_pool_ReleaseClone(picture_t *clone)<br> <br> picture_Release(picture);<br> <br>- vlc_mutex_lock(&pool->lock);<br>+ vlc_mutex_lock(&pool->cancel.lock);<br> assert(!(pool->available & (1ULL << offset)));<br> pool->available |= 1ULL << offset;<br>- vlc_cond_signal(&pool->wait);<br>- vlc_mutex_unlock(&pool->lock);<br>+ vlc_cond_signal(&pool->cancel.wait);<br>+ vlc_mutex_unlock(&pool->cancel.lock);<br> <br> picture_pool_Destroy(pool);<br> }<br>@@ -107,8 +105,8 @@ picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab)<br> if (unlikely(pool == NULL))<br> return NULL;<br> <br>- vlc_mutex_init(&pool->lock);<br>- vlc_cond_init(&pool->wait);<br>+ vlc_cancelable_Init( &pool->cancel );<br>+<br> if (count == POOL_MAX)<br> pool->available = ~0ULL;<br> else<br>@@ -116,7 +114,6 @@ picture_pool_t *picture_pool_New(unsigned count, picture_t *const *tab)<br> atomic_init(&pool->refs, 1);<br> pool->picture_count = count;<br> memcpy(pool->picture, tab, count * sizeof (picture_t *));<br>- pool->canceled = false;<br> return pool;<br> }<br> <br>@@ -171,7 +168,7 @@ picture_t *picture_pool_Get(picture_pool_t *pool)<br> {<br> unsigned long long available;<br> <br>- vlc_mutex_lock(&pool->lock);<br>+ vlc_mutex_lock(&pool->cancel.lock);<br> assert(pool->refs > 0);<br> available = pool->available;<br> <br>@@ -179,11 +176,11 @@ picture_t *picture_pool_Get(picture_pool_t *pool)<br> {<br> int i = ctz(available);<br> <br>- if (unlikely(pool->canceled))<br>+ if (unlikely(pool->cancel.canceled))<br> break;<br> <br> pool->available &= ~(1ULL << i);<br>- vlc_mutex_unlock(&pool->lock);<br>+ vlc_mutex_unlock(&pool->cancel.lock);<br> available &= ~(1ULL << i);<br> <br> picture_t *clone = picture_pool_ClonePicture(pool, i);<br>@@ -194,28 +191,27 @@ picture_t *picture_pool_Get(picture_pool_t *pool)<br> return clone;<br> }<br> <br>- vlc_mutex_unlock(&pool->lock);<br>+ vlc_mutex_unlock(&pool->cancel.lock);<br> return NULL;<br> }<br> <br> picture_t *picture_pool_Wait(picture_pool_t *pool)<br> {<br>- vlc_mutex_lock(&pool->lock);<br>+ vlc_mutex_lock(&pool->cancel.lock);<br> assert(pool->refs > 0);<br> <br> while (pool->available == 0)<br> {<br>- if (pool->canceled)<br>+ if (!vlc_cancelable_Wait(&pool->cancel))<br> {<br>- vlc_mutex_unlock(&pool->lock);<br>+ vlc_mutex_unlock(&pool->cancel.lock);<br> return NULL;<br> }<br>- vlc_cond_wait(&pool->wait, &pool->lock);<br> }<br> <br> int i = ctz(pool->available);<br> pool->available &= ~(1ULL << i);<br>- vlc_mutex_unlock(&pool->lock);<br>+ vlc_mutex_unlock(&pool->cancel.lock);<br> <br> picture_t *clone = picture_pool_ClonePicture(pool, i);<br> if (clone != NULL) {<br>@@ -227,16 +223,38 @@ picture_t *picture_pool_Wait(picture_pool_t *pool)<br> <br> void picture_pool_Cancel(picture_pool_t *pool, bool canceled)<br> {<br>- vlc_mutex_lock(&pool->lock);<br> assert(pool->refs > 0);<br>-<br>- pool->canceled = canceled;<br>- if (canceled)<br>- vlc_cond_broadcast(&pool->wait);<br>- vlc_mutex_unlock(&pool->lock);<br>+ vlc_cancelable_SetCanceled( &pool->cancel, canceled );<br> }<br> <br> unsigned picture_pool_GetSize(const picture_pool_t *pool)<br> {<br> return pool->picture_count;<br> }<br>+<br>+<br>+void vlc_cancelable_Init(vlc_cancelable *cancel)<br>+{<br>+ vlc_mutex_init(&cancel->lock);<br>+ vlc_cond_init(&cancel->wait);<br>+ cancel->canceled = false;<br>+}<br>+<br>+bool vlc_cancelable_Wait(vlc_cancelable *cancel)<br>+{<br>+ vlc_mutex_assert(&cancel->lock);<br>+ if (cancel->canceled)<br>+ return false;<br>+<br>+ vlc_cond_wait(&cancel->wait, &cancel->lock);<br>+ return true;<br>+}<br>+<br>+void vlc_cancelable_SetCanceled(vlc_cancelable *cancel, bool canceled)<br>+{<br>+ vlc_mutex_lock(&cancel->lock);<br>+ cancel->canceled = canceled;<br>+ if (canceled)<br>+ vlc_cond_broadcast(&cancel->wait);<br>+ vlc_mutex_unlock(&cancel->lock);<br>+}</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>