[LTP] [PATCH 1/4] lib: Fix initialization of recursive mutex

Cyril Hrubis chrubis@suse.cz
Wed Aug 17 16:13:59 CEST 2022


Hi!
> Signed-off-by: Tudor Cretu <tudor.cretu@arm.com>
> ---
>  lib/tst_res.c | 25 +++++++++++++++++--------
>  1 file changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/tst_res.c b/lib/tst_res.c
> index 8d86b48a4..2f66ec40c 100644
> --- a/lib/tst_res.c
> +++ b/lib/tst_res.c
> @@ -82,17 +82,27 @@ void *TST_RET_PTR;
>  	assert(strlen(buf) > 0);		\
>  } while (0)
>  
> -#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
> -# ifdef __ANDROID__
> -#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
> -	PTHREAD_RECURSIVE_MUTEX_INITIALIZER
> -# else
> -/* MUSL: http://www.openwall.com/lists/musl/2017/02/20/5 */
> -#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP  { {PTHREAD_MUTEX_RECURSIVE} }
> -# endif
> +#if !defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) && defined(__ANDROID__)
> +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
>  #endif
>  
> +#ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
>  static pthread_mutex_t tmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
> +#else
> +/* MUSL: http://www.openwall.com/lists/musl/2017/02/20/5 */

I would have put this URL to the commit message instead, otherwise the
change looks good.

> +static pthread_mutex_t tmutex;
> +
> +__attribute__((constructor))
> +static void init_tmutex(void)
> +{
> +	pthread_mutexattr_t mutattr = {0};
> +
> +	pthread_mutexattr_init(&mutattr);
> +	pthread_mutexattr_settype(&mutattr, PTHREAD_MUTEX_RECURSIVE);
> +	pthread_mutex_init(&tmutex, &mutattr);
> +	pthread_mutexattr_destroy(&mutattr);
> +}
> +#endif
>  
>  static void check_env(void);
>  static void tst_condense(int tnum, int ttype, const char *tmesg);
> -- 
> 2.25.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list