[vlc-devel] [PATCH v2] thread: fix compilation with clang 7 or older
robux4 at ycbcr.xyz
Mon Mar 2 09:28:58 CET 2020
On 2020-03-02 8:53, Marvin Scholz wrote:
> C11's atomic_load_explicit did not allow a const qualified first
> argument, even though it never modifies it (see DR459).
> Clang versions 7 or older did implement this quite strictly and
> therefore errors when compiling this code:
> address argument to atomic operation must be a pointer to non-const
> _Atomic type ('const _Atomic(const void *) *' invalid)
> See https://reviews.llvm.org/D47618 and https://reviews.llvm.org/D47613
> src/misc/threads.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
> diff --git a/src/misc/threads.c b/src/misc/threads.c
> index ea78e37453..db90a27240 100644
> --- a/src/misc/threads.c
> +++ b/src/misc/threads.c
> @@ -135,11 +135,21 @@ static _Thread_local char thread_self;
> bool vlc_mutex_held(const vlc_mutex_t *mtx)
> +#if defined(__clang__) && !defined(__apple_build_version__) && (__clang_major__ < 8)
The Apple 7- versions don't have this issue ?
IMO it's OK not to add the distinction for this compiler flavor.
Otherwsise we'd have to check which version from which vendor has the issue.
> + /* The explicit cast to non-const is needed to workaround a clang
> + * error with clang 7 or lower, as atomic_load_explicit in C11 did not
> + * allow its first argument to be const-qualified (see DR459)
> + */
> + vlc_mutex_t *tmp_mtx = (vlc_mutex_t *)mtx;
> + const vlc_mutex_t *tmp_mtx = mtx;
> /* This comparison is thread-safe:
> * Even though other threads may modify the owner field at any time,
> * they will never make it compare equal to the calling thread.
> - return THREAD_SELF == atomic_load_explicit(&mtx->owner,
> + return THREAD_SELF == atomic_load_explicit(&tmp_mtx->owner,
> 2.21.1 (Apple Git-122.3)
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
More information about the vlc-devel