[vlc-commits] threads: store the condition variable value as an atomic_uint with LIBVLC_NEED_CONDVAR
Steve Lhomme
git at videolan.org
Mon Feb 10 14:54:10 CET 2020
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Feb 7 15:55:28 2020 +0100| [2f761fe4a1ccb0cc6455ebe6c048c9ef2544941a] | committer: Steve Lhomme
threads: store the condition variable value as an atomic_uint with LIBVLC_NEED_CONDVAR
We can include stdatomic.h in the headers, we do it in many places. But we
can't use it with C++ because the std:atomic_int storage is likely different
and can be initialized/released the same way.
We change the static assert in the core to make sure the type in the union that
will be used for storage by C++ modules is correct.
In C++11 there is std::condition_variable anyway. The vlc_cond_t would only be
useful to share it with C code in a module or legacy C++ code.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2f761fe4a1ccb0cc6455ebe6c048c9ef2544941a
---
include/vlc_threads.h | 7 ++++++-
src/misc/threads.c | 8 ++++----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 1598c9c804..68b98b6b33 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -357,7 +357,12 @@ typedef struct vlc_timer *vlc_timer_t;
typedef struct
{
- unsigned value;
+ union {
+#ifndef __cplusplus
+ atomic_uint value;
+#endif
+ int cpp_value;
+ };
} vlc_cond_t;
# define VLC_STATIC_COND { 0 }
#endif
diff --git a/src/misc/threads.c b/src/misc/threads.c
index b40348ca90..7edb369bed 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -200,12 +200,12 @@ void (vlc_tick_sleep)(vlc_tick_t delay)
static inline atomic_uint *vlc_cond_value(vlc_cond_t *cond)
{
- /* XXX: ugly but avoids including stdatomic.h in vlc_threads.h */
- static_assert (sizeof (cond->value) <= sizeof (atomic_uint),
+ /* 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->value) % alignof (atomic_uint)) == 0,
+ static_assert ((alignof (cond->cpp_value) % alignof (cond->value)) == 0,
"Alignment mismatch");
- return (atomic_uint *)&cond->value;
+ return &cond->value;
}
void vlc_cond_init(vlc_cond_t *cond)
More information about the vlc-commits
mailing list