[vlc-devel] [PATCH] thread: rectify atomic_uint-related assertions

RĂ©mi Denis-Courmont remi at remlab.net
Sun Feb 16 21:30:18 CET 2020


---
 src/misc/threads.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/misc/threads.c b/src/misc/threads.c
index 49be4441b9..b5a63ae272 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -30,6 +30,14 @@
 #include <vlc_common.h>
 #include "libvlc.h"
 
+/* <stdatomic.h> types cannot be used in the C++ view of <vlc_threads.h> */
+struct vlc_suuint { union { unsigned int value; }; };
+
+static_assert (sizeof (atomic_uint) <= sizeof (struct vlc_suuint),
+               "Size mismatch");
+static_assert (alignof (atomic_uint) <= alignof (struct vlc_suuint),
+               "Alignment mismatch");
+
 /*** Global locks ***/
 
 void vlc_global_mutex (unsigned n, bool acquire)
@@ -197,15 +205,8 @@ void (vlc_tick_sleep)(vlc_tick_t delay)
 #endif
 
 #ifdef LIBVLC_NEED_CONDVAR
-#include <stdalign.h>
-
 void vlc_cond_init(vlc_cond_t *cond)
 {
-    /* Don't use C++ atomic types in vlc_threads.h for the C atomic storage */
-    static_assert (sizeof (cond->cpp_value) <= sizeof (cond->value),
-                   "Size mismatch!");
-    static_assert ((alignof (cond->cpp_value) % alignof (cond->value)) == 0,
-                   "Alignment mismatch");
     /* Initial value is irrelevant but set it for happy debuggers */
     atomic_init(&cond->value, 0);
 }
-- 
2.25.0



More information about the vlc-devel mailing list