From de8b99e2f04f94313a7748adedf7535603013951 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 15 May 2013 11:51:22 +0200 Subject: Implement valgrind's hellgrind checks for threading problems And cleanup our locks/locking model. There's no need to use recursive locks, especially since we can't use them on all platforms. In addition adjust taking of locks during initialization so that there's no chance of deadlocking here. --- automaint.sh | 2 +- build/Makefile.decl | 5 +++++ build/Makefile.tests | 5 +++++ common/compat.c | 2 +- p11-kit/modules.c | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/automaint.sh b/automaint.sh index 975556d..96cb60c 100755 --- a/automaint.sh +++ b/automaint.sh @@ -41,7 +41,7 @@ done echo ' done' done - for target in distcheck memcheck leakcheck install upload-coverage \ + for target in distcheck memcheck leakcheck hellcheck install upload-coverage \ coverage upload-doc upload-release transifex; do echo "$target:" echo ' $(MAKE) -C ./local' $target diff --git a/build/Makefile.decl b/build/Makefile.decl index c90c22b..8dca4e7 100644 --- a/build/Makefile.decl +++ b/build/Makefile.decl @@ -9,3 +9,8 @@ leakcheck: @for dir in $(SUBDIRS); do \ test "$$dir" = "." || $(MAKE) -C $$dir leakcheck; \ done + +hellcheck: + @for dir in $(SUBDIRS); do \ + test "$$dir" = "." || $(MAKE) -C $$dir hellcheck; \ + done diff --git a/build/Makefile.tests b/build/Makefile.tests index 3faa7f3..0c5b85c 100644 --- a/build/Makefile.tests +++ b/build/Makefile.tests @@ -12,8 +12,13 @@ MEMCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=80 --quiet --trace-child LEAKCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=81 --quiet --leak-check=yes +HELLCHECK_ENV = $(TEST_RUNNER) valgrind --error-exitcode=82 --quiet --tool=helgrind + memcheck: all make $(AM_MAKEFLAGS) TESTS_ENVIRONMENT="$(MEMCHECK_ENV)" check-TESTS leakcheck: all make $(AM_MAKEFLAGS) TESTS_ENVIRONMENT="$(LEAKCHECK_ENV)" check-TESTS + +hellcheck: all + make $(AM_MAKEFLAGS) TESTS_ENVIRONMENT="$(HELLCHECK_ENV)" check-TESTS diff --git a/common/compat.c b/common/compat.c index 4d8d73c..b8ed2ad 100644 --- a/common/compat.c +++ b/common/compat.c @@ -161,7 +161,7 @@ p11_mutex_init (p11_mutex_t *mutex) int ret; pthread_mutexattr_init (&attr); - pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_DEFAULT); ret = pthread_mutex_init (mutex, &attr); assert (ret == 0); pthread_mutexattr_destroy (&attr); diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 19ba895..e62a43c 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -531,8 +531,8 @@ initialize_module_unlocked_reentrant (Module *mod) mod->initialize_thread = self; /* Change over to the module specific mutex */ - p11_mutex_lock (&mod->initialize_mutex); p11_unlock (); + p11_mutex_lock (&mod->initialize_mutex); if (!mod->initialize_called) { assert (mod->funcs); -- cgit v1.1