<html><head></head><body>Ok. Do we have any relevant platform where unions have high alignment than uint regardless of their members?<br><br><div class="gmail_quote">Le 10 février 2020 11:02:21 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 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)</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>