<html><head></head><body>Hi,<br><br>I intended to do something like that, yes. But the static inline is no longer useful then.<br><br><div class="gmail_quote">Le 7 février 2020 17:02:10 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 a5425236b1c..075083d1005 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_int 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 7699cfae05d..47bf1dfcb14 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_int *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_int),<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_int)) == 0,<br>+ static_assert ((alignof (cond->cpp_value) % alignof (cond->value)) == 0,<br> "Alignment mismatch");<br>- return (atomic_int *)&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>