<html><head></head><body>Hi,<br><br>I was referring to (not) needlessly increasing the size of vlc_cond_t, which would occur if union alignment is 8 or 16 bytes.<br><br>Regardless, the current CV implementation has a wake-up loss bug, and I need to change the definition of vlc_cond_t to address it, so this is beating a dead horse.<br><br><div class="gmail_quote">Le 10 février 2020 14:06:06 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">On 2020-02-10 11:52, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">Ok. Do we have any relevant platform where unions have high alignment <br>than uint regardless of their members?<br></blockquote><br>No idea. But it's probably safer not too assume too many things.<br><br>Also we're assuming the alignment of the structure in C code is the same <br>as the structure in C++. Maybe it's not.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">Le 10 février 2020 11:02:21 GMT+02:00, Steve Lhomme <robux4@ycbcr.xyz> a <br>écrit :<br><br> We can include stdatomic.h in the headers, we do it in many places. But we<br> can't use it with C++ because the std:atomic_int storage is likely different<br> and can be initialized/released the same way.<br><br> We change the static assert in the core to make sure the type in the union that<br> will be used for storage by C++ modules is correct.<hr> include/vlc_threads.h | 12 +++++++++++-<br> src/misc/threads.c | 8 ++++----<br> 2 files changed, 15 insertions(+), 5 deletions(-)<br><br> diff --git a/include/vlc_threads.h b/include/vlc_threads.h<br> index f30f0699e37..1a05e57b82c 100644<br> --- a/include/vlc_threads.h<br> +++ b/include/vlc_threads.h<br> @@ -351,9 +351,19 @@ typedef struct vlc_timer *vlc_timer_t;<br> #endif<br> <br> #ifdef LIBVLC_NEED_CONDVAR<br> +#ifndef __cplusplus<br> +#include <stdatomic.h><br> +#endif<br> +<br> +<br> typedef struct<br> {<br> - unsigned value;<br> + union {<br> +#ifndef __cplusplus<br> + atomic_uint value;<br> +#endif<br> + int cpp_value;<br> + };<br> } vlc_cond_t;<br> # define VLC_STATIC_COND { 0 }<br> #endif<br> diff --git a/src/misc/threads.c b/src/misc/threads.c<br> index 18855e85bd4..304ae972199 100644<br> --- a/src/misc/threads.c<br> +++ b/src/misc/threads.c<br> @@ -210,12 +210,12 @@ void (vlc_tick_sleep)(vlc_tick_t delay)<br> <br> static inline atomic_uint *vlc_cond_value(vlc_cond_t *cond)<br> {<br> - /* XXX: ugly but avoids including stdatomic.h in vlc_threads.h */<br> - static_assert (sizeof (cond->value) <= sizeof (atomic_uint),<br> + /* Don't use C++ atomic types in vlc_threads.h for the C atomic storage */<br> + static_assert (sizeof (cond->cpp_value) <= sizeof (cond->value),<br> "Size mismatch!");<br> - static_assert ((alignof (cond->value) % alignof (atomic_uint)) == 0,<br> + static_assert ((alignof (cond->cpp_value) % alignof (cond->value)) == 0,<br> "Alignment mismatch");<br> - return (atomic_uint *)&cond->value;<br> + return &cond->value;<br> }<br> <br> void vlc_cond_init(vlc_cond_t *cond)<br><br><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser <br>ma brièveté.<hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>