From 620de68bea6fa4e287d565b293202114200deec4 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 13 Aug 2005 03:26:18 +0000 Subject: [PATCH] Turn the mutex code back on. It looks like the deadlocks have disappeared as of the cairo_scaled_font_map patch from two days ago. Setup an automake conditional for the HAVE_PTHREAD case. Link all tests with -lpthread if available, so that we can get some testing of cairo with mutexes turned on. --- ChangeLog | 16 ++++++++++++++++ configure.in | 7 ++----- src/cairoint.h | 41 +++++++++-------------------------------- test/Makefile.am | 4 ++++ 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4da8b438a..7ddad3a45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2005-08-13 Carl Worth + + * src/cairoint.h: Turn the mutex code back on. It looks like the + deadlocks have disappeared as of the cairo_scaled_font_map patch + from two days ago. + + * configure.in: Setup an automake conditional for the HAVE_PTHREAD + case. + + * test/Makefile.am: Link all tests with -lpthread if available, so + that we can get some testing of cairo with mutexes turned on. + +2005-08-13 Carl Worth + + * src/cairoint.h: + 2005-08-13 Carl Worth Minor, cosmetic changes: diff --git a/configure.in b/configure.in index af077849f..66513578b 100644 --- a/configure.in +++ b/configure.in @@ -330,11 +330,8 @@ AC_SUBST(FT_FONT_FEATURE) dnl =========================================================================== -# -# The FreeType backend uses pthread locking when avaialble -# - -AC_CHECK_HEADERS([pthread.h]) +AC_CHECK_HEADERS([pthread.h], have_pthread=yes, have_pthread=no) +AM_CONDITIONAL(HAVE_PTHREAD, test "x$have_pthread" = "xyes") dnl =========================================================================== diff --git a/src/cairoint.h b/src/cairoint.h index b71e9dfd8..2fbf335f0 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -117,43 +117,20 @@ #define __attribute__(x) #endif -/* XXX: There's a bad bug in the cache locking code that attempts to - * recursively lock a mutex, (which we shouldn't actually need to ever - * do). This leads to deadlocks in even single-threaded applications, - * (if they link with -lpthread). - * - * For now, we're removing all mutex locking, which leaves things at - * the same level of non-thread-safeness that we've had in every - * snapshot since the cache code first landed. - * - * I'm rewriting the cache code now and plan to have thread-safe, - * locking caches working before the next snapshot. CDW. - */ - -#if CAIRO_CACHE_CODE_IS_FIXED_TO_NOT_DEADLOCK_SINGLE_THREADED_APPLICATIONS - -# if HAVE_PTHREAD_H -# define CAIRO_MUTEX_DECLARE(name) static pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER -# define CAIRO_MUTEX_DECLARE_GLOBAL(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER -# define CAIRO_MUTEX_LOCK(name) pthread_mutex_lock (&name) -# define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&name) -# endif - -# ifndef CAIRO_MUTEX_DECLARE -# warning "No mutex declarations, assuming single-threaded code" -# define CAIRO_MUTEX_DECLARE(name) -# define CAIRO_MUTEX_DECLARE_GLOBAL(name) -# define CAIRO_MUTEX_LOCK(name) -# define CAIRO_MUTEX_UNLOCK(name) -# endif - -#else +#if HAVE_PTHREAD_H +# include +# define CAIRO_MUTEX_DECLARE(name) static pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER +#define CAIRO_MUTEX_DECLARE_GLOBAL(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER +# define CAIRO_MUTEX_LOCK(name) pthread_mutex_lock (&name) +# define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&name) +#endif +#ifndef CAIRO_MUTEX_DECLARE +# warning "No mutex declarations, assuming single-threaded code" # define CAIRO_MUTEX_DECLARE(name) # define CAIRO_MUTEX_DECLARE_GLOBAL(name) # define CAIRO_MUTEX_LOCK(name) # define CAIRO_MUTEX_UNLOCK(name) - #endif #define MIN(a, b) ((a) < (b) ? (a) : (b)) diff --git a/test/Makefile.am b/test/Makefile.am index 27d8b373f..5475525d4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -155,6 +155,10 @@ xmalloc.h LDADDS = libcairotest.la $(top_builddir)/src/libcairo.la +if HAVE_PTHREAD +LDADDS += -lpthread +endif + # ARGH! I have to repeat the list of tests a third time. Maybe it's # time to break down and auto-generate the Makefile.am or something # from autogen.sh. My, but this is painful...