From d48bb4fbe876a93199ba48fcf5f32734fbe18ba9 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 1 Mar 2007 23:34:34 -0800 Subject: [PATCH] Implement CAIRO_MUTEX_INIT with memcpy instead of pthread_mutex_init The trick here is that with the weak symbol support for pthreads, pthread_mutex_init can be a NOP leaving the mutex uninitialized. Then, if some pthread-using library is dynamically loaded, the non-NOP pthread functions get used and we end up trying to lock an uninitialized mutex. This should fix the bugs reported here: Cairo 1.3.14 deadlocks in cairo_scaled_font_glyph_extents or _cairo_ft_unscaled_font_lock_face https://bugs.freedesktop.org/show_bug.cgi?id=10035 --- src/cairoint.h | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/src/cairoint.h b/src/cairoint.h index 890929f..3a2d845 100755 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -141,7 +141,10 @@ CAIRO_BEGIN_DECLS # define CAIRO_MUTEX_LOCK(name) pthread_mutex_lock (&name) # define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&name) typedef pthread_mutex_t cairo_mutex_t; -# define CAIRO_MUTEX_INIT(mutex) pthread_mutex_init ((mutex), NULL) +#define CAIRO_MUTEX_INIT(mutex) do { \ + pthread_mutex_t tmp_mutex = PTHREAD_MUTEX_INITIALIZER; \ + memcpy (mutex, &tmp_mutex, sizeof (tmp_mutex)); \ +} while (0) # define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (mutex) # define CAIRO_MUTEX_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER #endif -- 1.5.0.rc1.gf4b6c