Blob Blame History Raw
From 290193ffde359536a3c92fd28e49d0001299b1aa Mon Sep 17 00:00:00 2001
From: Nils Philippsen <nils@redhat.com>
Date: Fri, 13 Feb 2015 17:29:39 +0100
Subject: [PATCH] patch: concurrency-stresstest

Squashed commit of the following:

commit 0df44e20b530e02faee169150d282950b78868b2
Author: Nils Philippsen <nils@redhat.com>
Date:   Fri Feb 13 13:29:13 2015 +0100

    Remove workaround for non-recursive mutexes.

    This workaround caused concurrency-stress-test to fail occasionally.
    Meanwhile BablMutex wraps pthread mutexes in a way that they are
    initialized as recursive.

    This partially reverts commit 9d2aa7d13ac421935de1e87301c48af50b0ceb59.

    (cherry picked from commit 81ef6f201164c81876028a506b00b52976041741)

commit 90634a3998bf59e5fba77520f27b0016c601592a
Author: Nils Philippsen <nils@redhat.com>
Date:   Fri Feb 13 13:24:52 2015 +0100

    Make BablMutex recursive on all platforms.

    Win32 Critical Sections are recursive locks, initialize pthread mutexes
    as recursive as well.

    (cherry picked from commit 6bf8a87b83f56e26d947acd5fab78370c4902a26)
---
 babl.pc.in             | 3 ++-
 babl/Makefile.am       | 2 +-
 babl/babl-fish-path.c  | 6 ++----
 babl/babl-mutex.c      | 7 ++++++-
 configure.ac           | 3 +++
 extensions/Makefile.am | 3 ++-
 tests/Makefile.am      | 2 +-
 tools/Makefile.am      | 4 ++--
 8 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/babl.pc.in b/babl.pc.in
index 76b5e69..3f2049f 100644
--- a/babl.pc.in
+++ b/babl.pc.in
@@ -7,4 +7,5 @@ Name: babl
 Description: Dynamic, any to any, pixel format conversion library
 Version: @BABL_REAL_VERSION@
 Cflags: -I${includedir}/@PACKAGE_NAME@-@BABL_API_VERSION@
-Libs: -L${libdir} -l@PACKAGE_NAME@-@BABL_API_VERSION@ @MATH_LIB@
+Libs: -L${libdir} -l@PACKAGE_NAME@-@BABL_API_VERSION@
+Libs.private: @MATH_LIB@ @THREAD_LIB@
diff --git a/babl/Makefile.am b/babl/Makefile.am
index 4f59447..6827faa 100644
--- a/babl/Makefile.am
+++ b/babl/Makefile.am
@@ -86,7 +86,7 @@ libbabl_@BABL_API_VERSION@_la_LIBADD=\
 	@LTLIBOBJS@
 
 libbabl_@BABL_API_VERSION@_la_LDFLAGS= 		\
-	${no_undefined} $(MATH_LIB)	\
+	${no_undefined} $(MATH_LIB) $(THREAD_LIB) \
 	-version-info $(BABL_LIBRARY_VERSION)
 
 EXTRA_DIST = babl-ref-pixels.inc
diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c
index 5dc0601..bf9c520 100644
--- a/babl/babl-fish-path.c
+++ b/babl/babl-fish-path.c
@@ -300,8 +300,7 @@ babl_fish_path (const Babl *source,
     pc.fish_path = babl;
     pc.to_format = (Babl *) destination;
 
-    if (babl_in_fish_path <= 0)
-      babl_mutex_lock (babl_format_mutex);
+    babl_mutex_lock (babl_format_mutex);
     /* we hold a global lock whilerunning get_conversion_path since
      * it depends on keeping the various format.visited members in
      * a consistent state, this code path is not performance critical
@@ -312,8 +311,7 @@ babl_fish_path (const Babl *source,
     get_conversion_path (&pc, (Babl *) source, 0, max_path_length ());
 
     babl_in_fish_path--;
-    if (babl_in_fish_path <= 0)
-      babl_mutex_unlock (babl_format_mutex);
+    babl_mutex_unlock (babl_format_mutex);
     babl_free (pc.current_path);
   }
 
diff --git a/babl/babl-mutex.c b/babl/babl-mutex.c
index 3f82cc5..eacd372 100644
--- a/babl/babl-mutex.c
+++ b/babl/babl-mutex.c
@@ -30,7 +30,12 @@ babl_mutex_new (void)
 #ifdef _WIN32
   InitializeCriticalSection (mutex);
 #else
-  pthread_mutex_init (mutex, NULL);
+  pthread_mutexattr_t mutexattr;
+
+  pthread_mutexattr_init (&mutexattr);
+  pthread_mutexattr_settype (&mutexattr, PTHREAD_MUTEX_RECURSIVE);
+  pthread_mutex_init (mutex, &mutexattr);
+  pthread_mutexattr_destroy (&mutexattr);
 #endif
   return mutex;
 }
diff --git a/configure.ac b/configure.ac
index b07d4d5..3ed6404 100644
--- a/configure.ac
+++ b/configure.ac
@@ -254,6 +254,7 @@ AC_MSG_RESULT([$platform_win32])
 AM_CONDITIONAL(PLATFORM_WIN32, test "$platform_win32" = "yes")
 
 MATH_LIB=-lm
+THREAD_LIB=-lpthread
 AC_MSG_CHECKING([for native Win32])
 case "$target_or_host" in
   *-*-mingw*)
@@ -261,6 +262,7 @@ case "$target_or_host" in
     PATH_SEP=';'
     DIR_SEP='\\'
     MATH_LIB=
+    THREAD_LIB=
     ;;
   *)
     os_win32=no
@@ -272,6 +274,7 @@ AC_MSG_RESULT([$os_win32])
 AC_SUBST(PATH_SEP)
 AC_SUBST(DIR_SEP)
 AC_SUBST(MATH_LIB)
+AC_SUBST(THREAD_LIB)
 
 AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
 AM_CONDITIONAL(OS_UNIX, test "$os_win32" != "yes")
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 3954739..4a3fb8a 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -53,7 +53,8 @@ ycbcr_la_SOURCES = ycbcr.c
 float_la_SOURCES = float.c
 fast_float_la_SOURCES = fast-float.c
 
-LIBS = $(top_builddir)/babl/libbabl-@BABL_API_VERSION@.la $(MATH_LIB)
+LIBS = $(top_builddir)/babl/libbabl-@BABL_API_VERSION@.la $(MATH_LIB) \
+	$(THREAD_LIB)
 
 sse2_float_la_CFLAGS = $(SSE2_EXTRA_CFLAGS)
 sse2_int8_la_CFLAGS = $(SSE2_EXTRA_CFLAGS)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2733a28..6e282af 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,7 +35,7 @@ AM_LDFLAGS  = -pthread
 endif
 
 LDADD = $(top_builddir)/babl/libbabl-@BABL_API_VERSION@.la \
-	$(MATH_LIB)
+	$(MATH_LIB) $(THREAD_LIB)
 
 EXTRA_DIST=common.inc
 
diff --git a/tools/Makefile.am b/tools/Makefile.am
index f67a66e..ad54455 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,9 +1,9 @@
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/babl
 
 LDADD = $(top_builddir)/babl/libbabl-@BABL_API_VERSION@.la \
-	$(MATH_LIB)
+	$(MATH_LIB) $(THREAD_LIB)
 
 if HAVE_SRANDOM
 noinst_PROGRAMS =		\
 	babl-gen-test-pixels
-endif
\ No newline at end of file
+endif
-- 
2.1.0