From 09169e90d07707dd089c2f24644c383ff4630337 Mon Sep 17 00:00:00 2001 From: Moonhee Choi Date: Fri, 1 Jun 2018 17:28:49 +0900 Subject: [PATCH] [P180523-02901] Fix a crash occurred by thread unsafe issue Change-Id: I78792c2dc09e4c44c51ffedaea5f73de0ee87e4c Signed-off-by: Moonhee Choi --- src/cairo-image-surface-private.h | 1 + src/cairo-image-surface.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cairo-image-surface-private.h b/src/cairo-image-surface-private.h index 8ca694c..9dc7ac5 100644 --- a/src/cairo-image-surface-private.h +++ b/src/cairo-image-surface-private.h @@ -77,6 +77,7 @@ struct _cairo_image_surface { unsigned owns_data : 1; unsigned transparency : 2; unsigned color : 2; + unsigned shadow_cache_init : 1; }; #define to_image_surface(S) ((cairo_image_surface_t *)(S)) diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index a399a81..bf8e262 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -96,12 +96,15 @@ static cairo_atomic_int_t shadow_caches_ref_count = 0; static void _cairo_image_shadow_caches_init (void) { + CAIRO_RECURSIVE_MUTEX_INIT (shadow_caches_mutex); + CAIRO_MUTEX_LOCK (shadow_caches_mutex); + _cairo_atomic_int_inc (&shadow_caches_ref_count); if (shadow_caches_ref_count == 1) cairo_list_init (&shadow_caches); - CAIRO_RECURSIVE_MUTEX_INIT (shadow_caches_mutex); + CAIRO_MUTEX_UNLOCK (shadow_caches_mutex); } static void @@ -140,6 +143,11 @@ _cairo_image_surface_shadow_cache_acquire (void *abstract_surface) if (unlikely (surface->base.status)) return surface->base.status; + if (!surface->shadow_cache_init) { + _cairo_image_shadow_caches_init(); + surface->shadow_cache_init = 1; + } + CAIRO_MUTEX_LOCK (shadow_caches_mutex); shadow_caches_mutex_depth++; @@ -174,6 +182,11 @@ _cairo_image_surface_get_shadow_cache (void *abstract_surface) if (unlikely (surface->base.status)) return NULL; + if (!surface->shadow_cache_init) { + _cairo_image_shadow_caches_init(); + surface->shadow_cache_init = 1; + } + return &shadow_caches; } @@ -295,7 +308,7 @@ _cairo_image_surface_init (cairo_image_surface_t *surface, surface->compositor = _cairo_image_spans_compositor_get (); - _cairo_image_shadow_caches_init (); + surface->shadow_cache_init = 0; CAIRO_TRACE_END (__func__); } @@ -1006,7 +1019,10 @@ _cairo_image_surface_finish (void *abstract_surface) cairo_surface_destroy (parent); } - _cairo_image_shadow_caches_destroy (); + if (surface->shadow_cache_init) { + _cairo_image_shadow_caches_destroy (); + surface->shadow_cache_init = 0; + } CAIRO_TRACE_END (__func__); return CAIRO_STATUS_SUCCESS; -- 2.7.4