<html><head></head><body>Hi,<br><br>They're not specific to cond_init. The assertions should be in global context IMO (nit). Otherwise LGTM<br><br><div class="gmail_quote">Le 10 février 2020 11:02:22 GMT+02: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">We can use the atomic variable directly without any cast.<br><br>Only the C++ user need to be checked for the proper storage size/alignment of the variable they pass.<hr> src/misc/threads.c | 35 ++++++++++++++---------------------<br> 1 file changed, 14 insertions(+), 21 deletions(-)<br><br>diff --git a/src/misc/threads.c b/src/misc/threads.c<br>index 304ae972199..92d226cfb72 100644<br>--- a/src/misc/threads.c<br>+++ b/src/misc/threads.c<br>@@ -208,20 +208,15 @@ void (vlc_tick_sleep)(vlc_tick_t delay)<br> #ifdef LIBVLC_NEED_CONDVAR<br> #include <stdalign.h><br> <br>-static inline atomic_uint *vlc_cond_value(vlc_cond_t *cond)<br>+void vlc_cond_init(vlc_cond_t *cond)<br> {<br> /* Don't use C++ atomic types in vlc_threads.h for the C atomic storage */<br>+ /* Initial value is irrelevant but set it for happy debuggers */<br> static_assert (sizeof (cond->cpp_value) <= sizeof (cond->value),<br> "Size mismatch!");<br> static_assert ((alignof (cond->cpp_value) % alignof (cond->value)) == 0,<br> "Alignment mismatch");<br>- return &cond->value;<br>-}<br>-<br>-void vlc_cond_init(vlc_cond_t *cond)<br>-{<br>- /* Initial value is irrelevant but set it for happy debuggers */<br>- atomic_init(vlc_cond_value(cond), 0);<br>+ atomic_init(&cond->value, 0);<br> }<br> <br> void vlc_cond_init_daytime(vlc_cond_t *cond)<br>@@ -232,7 +227,7 @@ void vlc_cond_init_daytime(vlc_cond_t *cond)<br> void vlc_cond_destroy(vlc_cond_t *cond)<br> {<br> /* Tempting sanity check but actually incorrect:<br>- assert((atomic_load_explicit(vlc_cond_value(cond),<br>+ assert((atomic_load_explicit(&cond->value,<br> memory_order_relaxed) & 1) == 0);<br> * Due to timeouts and spurious wake-ups, the futex value can look like<br> * there are waiters, even though there are none. */<br>@@ -250,53 +245,51 @@ void vlc_cond_signal(vlc_cond_t *cond)<br> * - cnd_signal() sets the futex to the equal-or-next odd value, while<br> * - cnd_wait() sets the futex to the equal-or-next even value.<br> **/<br>- atomic_fetch_or_explicit(vlc_cond_value(cond), 1, memory_order_relaxed);<br>+ atomic_fetch_or_explicit(&cond->value, 1, memory_order_relaxed);<br> vlc_atomic_notify_one(&cond->value);<br> }<br> <br> void vlc_cond_broadcast(vlc_cond_t *cond)<br> {<br>- atomic_fetch_or_explicit(vlc_cond_value(cond), 1, memory_order_relaxed);<br>+ atomic_fetch_or_explicit(&cond->value, 1, memory_order_relaxed);<br> vlc_atomic_notify_all(&cond->value);<br> }<br> <br> void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)<br> {<br>- unsigned value = atomic_load_explicit(vlc_cond_value(cond),<br>- memory_order_relaxed);<br>+ unsigned value = atomic_load_explicit(&cond->value, memory_order_relaxed);<br> while (value & 1)<br> {<br>- if (atomic_compare_exchange_weak_explicit(vlc_cond_value(cond), &value,<br>+ if (atomic_compare_exchange_weak_explicit(&cond->value, &value,<br> value + 1,<br> memory_order_relaxed,<br> memory_order_relaxed))<br> value++;<br> }<br> <br>- vlc_cancel_addr_prepare(vlc_cond_value(cond));<br>+ vlc_cancel_addr_prepare(&cond->value);<br> vlc_mutex_unlock(mutex);<br> <br> vlc_atomic_wait(&cond->value, value);<br> <br> vlc_mutex_lock(mutex);<br>- vlc_cancel_addr_finish(vlc_cond_value(cond));<br>+ vlc_cancel_addr_finish(&cond->value);<br> }<br> <br> static int vlc_cond_wait_delay(vlc_cond_t *cond, vlc_mutex_t *mutex,<br> vlc_tick_t delay)<br> {<br>- unsigned value = atomic_load_explicit(vlc_cond_value(cond),<br>- memory_order_relaxed);<br>+ unsigned value = atomic_load_explicit(&cond->value, memory_order_relaxed);<br> while (value & 1)<br> {<br>- if (atomic_compare_exchange_weak_explicit(vlc_cond_value(cond), &value,<br>+ if (atomic_compare_exchange_weak_explicit(&cond->value, &value,<br> value + 1,<br> memory_order_relaxed,<br> memory_order_relaxed))<br> value++;<br> }<br> <br>- vlc_cancel_addr_prepare(vlc_cond_value(cond));<br>+ vlc_cancel_addr_prepare(&cond->value);<br> vlc_mutex_unlock(mutex);<br> <br> if (delay > 0)<br>@@ -305,7 +298,7 @@ static int vlc_cond_wait_delay(vlc_cond_t *cond, vlc_mutex_t *mutex,<br> value = 0;<br> <br> vlc_mutex_lock(mutex);<br>- vlc_cancel_addr_finish(vlc_cond_value(cond));<br>+ vlc_cancel_addr_finish(&cond->value);<br> <br> return value ? 0 : ETIMEDOUT;<br> }</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>