From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH V3 17/23] initialize recursive mutex in a portable way
Date: Wed, 27 Jul 2016 17:30:50 +0200 [thread overview]
Message-ID: <20160727153050.GF11986@rei.lan> (raw)
In-Reply-To: <20160722042656.22346-17-raj.khem@gmail.com>
Hi!
> diff --git a/include/mk/testcases.mk b/include/mk/testcases.mk
> index ea26d4f..eff0eee 100644
> --- a/include/mk/testcases.mk
> +++ b/include/mk/testcases.mk
> @@ -49,7 +49,7 @@ CPPFLAGS += -I$(abs_top_builddir)/$(TKI_DIR)
>
> INSTALL_DIR := testcases/bin
>
> -LDLIBS += -lltp
> +LDLIBS += -lltp -lpthread
>
> $(APICMDS_DIR) $(LIBLTP_DIR) $(abs_top_builddir)/$(TKI_DIR): %:
> mkdir -p "$@"
> diff --git a/lib/ltp.pc.in b/lib/ltp.pc.in
> index 9620129..63cd5f4 100644
> --- a/lib/ltp.pc.in
> +++ b/lib/ltp.pc.in
> @@ -6,5 +6,5 @@ libdir=@libdir@
> Name: LTP
> Description: Linux Test Project
> Version: @VERSION@
> -Libs: -L${libdir} -lltp
> +Libs: -L${libdir} -lltp -lpthread
> Cflags: -I${includedir}
> diff --git a/lib/newlib_tests/Makefile b/lib/newlib_tests/Makefile
> index 0e4eeb8..9dd69fd 100644
> --- a/lib/newlib_tests/Makefile
> +++ b/lib/newlib_tests/Makefile
> @@ -3,7 +3,7 @@ top_srcdir ?= ../..
> include $(top_srcdir)/include/mk/env_pre.mk
>
> CFLAGS += -W -Wall
> -LDLIBS += -lltp
> +LDLIBS += -lltp -lpthread
>
> test08: CFLAGS+=-pthread
> test09: CFLAGS+=-pthread
> diff --git a/lib/tests/Makefile b/lib/tests/Makefile
> index 73a0f16..bc4476d 100644
> --- a/lib/tests/Makefile
> +++ b/lib/tests/Makefile
> @@ -3,7 +3,7 @@ top_srcdir ?= ../..
> include $(top_srcdir)/include/mk/env_pre.mk
>
> CFLAGS += -W
> -LDLIBS += -lltp
> +LDLIBS += -lltp -lpthread
>
> tst_cleanup_once: CFLAGS += -pthread
This causes everything to be linked with pthreads which is enough for my
NACK for this patch.
> diff --git a/lib/tst_res.c b/lib/tst_res.c
> index b388d0d..ab995f8 100644
> --- a/lib/tst_res.c
> +++ b/lib/tst_res.c
> @@ -79,7 +79,8 @@ int TEST_ERRNO;
> assert(strlen(buf) > 0); \
> } while (0)
>
> -static pthread_mutex_t tmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
> +static pthread_once_t tmutex_once = PTHREAD_ONCE_INIT;
> +static pthread_mutex_t tmutex;
>
> static void check_env(void);
> static void tst_condense(int tnum, int ttype, const char *tmesg);
> @@ -142,9 +143,20 @@ const char *strttype(int ttype)
> #include "errnos.h"
> #include "signame.h"
>
> +static void init_tmutex(void)
> +{
> + pthread_mutexattr_t attr;
> +
> + pthread_mutexattr_init(&attr);
> + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
> + pthread_mutex_init(&tmutex, &attr);
> + pthread_mutexattr_destroy(&attr);
> +}
> +
> static void tst_res__(const char *file, const int lineno, int ttype,
> const char *arg_fmt, ...)
> {
> + pthread_once(&tmutex_once, init_tmutex);
> pthread_mutex_lock(&tmutex);
>
> char tmesg[USERMESG];
> @@ -233,6 +245,7 @@ void tst_flush(void)
> {
> NO_NEWLIB_ASSERT("Unknown", 0);
>
> + pthread_once(&tmutex_once, init_tmutex);
> pthread_mutex_lock(&tmutex);
>
> /*
> @@ -369,6 +382,7 @@ void tst_exit(void)
> {
> NO_NEWLIB_ASSERT("Unknown", 0);
>
> + pthread_once(&tmutex_once, init_tmutex);
> pthread_mutex_lock(&tmutex);
>
> tst_flush();
> @@ -441,6 +455,7 @@ static int tst_brk_entered = 0;
> static void tst_brk__(const char *file, const int lineno, int ttype,
> void (*func)(void), const char *arg_fmt, ...)
> {
> + pthread_once(&tmutex_once, init_tmutex);
> pthread_mutex_lock(&tmutex);
>
> char tmesg[USERMESG];
> @@ -505,6 +520,7 @@ void tst_resm_hexd_(const char *file, const int lineno, int ttype,
> {
> NO_NEWLIB_ASSERT(file, lineno);
>
> + pthread_once(&tmutex_once, init_tmutex);
> pthread_mutex_lock(&tmutex);
>
I do not like this.
I guess the easiest solution would be to eliminate the need for the
mutex to be recursive.
Which may be possible if we turn the T_exitval into counters and use
atomic operations to increment them which should us free from guarding
T_exitval updates called from tst_print() which are called from all over
the place. Or we can get rid of T_mode keeping only the default VERBOSE
behavior, which should have the same efect...
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2016-07-27 15:30 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-22 4:26 [LTP] [PATCH V3 01/23] Add knob to control whether numa support should be checked Khem Raj
2016-07-22 4:26 ` [LTP] [PATCH V3 02/23] Add knob to control tirpc support Khem Raj
2016-07-26 14:35 ` Cyril Hrubis
2016-07-26 14:56 ` Khem Raj
2016-07-22 4:26 ` [LTP] [PATCH V3 03/23] Remove including error.h, its unused Khem Raj
2016-07-26 15:05 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 04/23] Remove unused __BEGIN_DECLS and __END_DECLS Khem Raj
2016-07-26 15:39 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 05/23] guard mallocopt() with __GLIBC__ Khem Raj
2016-07-26 15:44 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 06/23] Use unsigned int instead of uint Khem Raj
2016-07-26 15:51 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 07/23] ptrace: Use int instead of enum __ptrace_request Khem Raj
[not found] ` <20160722042656.22346-7-raj.khem-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-07-26 16:03 ` Cyril Hrubis
2016-07-26 16:03 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 08/23] rt_sigaction/rt_sigprocmark: Replace SA_NOMASK with SA_NODEFER Khem Raj
2016-07-27 10:14 ` Cyril Hrubis
2016-07-27 15:14 ` Khem Raj
2016-07-27 15:35 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 09/23] mc_gethost: Use unsigned char instead of u_char Khem Raj
2016-07-27 10:20 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 10/23] sysconf01: Use _SC_2_C_VERSION conditionally Khem Raj
2016-08-01 15:36 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 11/23] lapi: Use sig_t instead of sighandler_t Khem Raj
2016-07-27 10:22 ` Cyril Hrubis
2016-07-27 15:15 ` Khem Raj
2016-07-27 16:03 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 12/23] trace_shed: Adapt to glibc 2.24 removal of union wait type Khem Raj
2016-08-01 15:22 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 13/23] vma03: fix page size offset as per page size alignment Khem Raj
2016-07-27 13:45 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 14/23] shmat1: Cover GNU specific code under __USE_GNU Khem Raj
2016-07-27 14:17 ` Cyril Hrubis
2016-07-27 15:20 ` Khem Raj
2016-07-22 4:26 ` [LTP] [PATCH V3 15/23] Add periodic output for long time test Khem Raj
2016-07-27 14:37 ` Cyril Hrubis
2016-07-27 15:21 ` Tudor Florea
2016-07-27 15:33 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 16/23] Fix test_proc_kill hanging Khem Raj
2016-07-27 14:46 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 17/23] initialize recursive mutex in a portable way Khem Raj
2016-07-27 15:30 ` Cyril Hrubis [this message]
2016-07-22 4:26 ` [LTP] [PATCH V3 18/23] replace SIGCLD with SIGCHLD Khem Raj
2016-07-27 16:24 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 19/23] creat06: Include limits.h for PATH_MAX Khem Raj
2016-08-01 12:49 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 20/23] fcntl34: Replace pthread_yield() with sched_yield() Khem Raj
2016-08-01 12:57 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 21/23] rename 'sigset' var to avoid shadowing with libc symbol sigset Khem Raj
2016-08-01 14:19 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 22/23] pec: Replace obsoleted SA_ONESHOT with SA_RESETHAND Khem Raj
2016-08-01 14:30 ` Cyril Hrubis
2016-07-22 4:26 ` [LTP] [PATCH V3 23/23] shmem_test_04: Include sys/types.h for caddr_t Khem Raj
2016-08-01 14:34 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160727153050.GF11986@rei.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.