summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-05-15 11:51:22 +0200
committerStef Walter <stefw@gnome.org>2013-05-15 11:51:22 +0200
commitde8b99e2f04f94313a7748adedf7535603013951 (patch)
tree2e9ce2fc6cc7cf1dfc86fd7af731b12f252cae59
parent4bd7eda265b94dfcb9a1db4aba756e1e05dd4f87 (diff)
downloadp11-kit-de8b99e2f04f94313a7748adedf7535603013951.tar.gz
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.
-rwxr-xr-xautomaint.sh2
-rw-r--r--build/Makefile.decl5
-rw-r--r--build/Makefile.tests5
-rw-r--r--common/compat.c2
-rw-r--r--p11-kit/modules.c2
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);