From 2fb20e990695537d67d6f3bbc3f13e2eed50f10f Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Mon, 1 Dec 2014 16:54:32 +0100 Subject: [PATCH] display: use a recursive mutex for the display cache. Use a recursive mutex for the display cache so that a 3rdparty display object could be initialized during the initialization of the parent display. --- gst-libs/gst/vaapi/gstvaapidisplay.c | 11 ++--- gst-libs/gst/vaapi/gstvaapidisplaycache.c | 55 +++++++++++++++++++---- gst-libs/gst/vaapi/gstvaapidisplaycache.h | 8 ++++ 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapidisplay.c b/gst-libs/gst/vaapi/gstvaapidisplay.c index a3b8a8ddd2..3f34a3ee88 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplay.c +++ b/gst-libs/gst/vaapi/gstvaapidisplay.c @@ -862,10 +862,11 @@ gst_vaapi_display_destroy (GstVaapiDisplay * display) gst_vaapi_display_replace_internal (&priv->parent, NULL); - g_mutex_lock (&g_display_cache_lock); - if (priv->cache) + if (priv->cache) { + gst_vaapi_display_cache_lock (priv->cache); gst_vaapi_display_cache_remove (priv->cache, display); - g_mutex_unlock (&g_display_cache_lock); + gst_vaapi_display_cache_unlock (priv->cache); + } gst_vaapi_display_cache_replace (&priv->cache, NULL); free_display_cache (); } @@ -953,9 +954,9 @@ gst_vaapi_display_create (GstVaapiDisplay * display, gst_vaapi_display_cache_replace (&priv->cache, cache); gst_vaapi_display_cache_unref (cache); - g_mutex_lock (&g_display_cache_lock); + gst_vaapi_display_cache_lock (cache); success = gst_vaapi_display_create_unlocked (display, init_type, init_value); - g_mutex_unlock (&g_display_cache_lock); + gst_vaapi_display_cache_unlock (cache); return success; } diff --git a/gst-libs/gst/vaapi/gstvaapidisplaycache.c b/gst-libs/gst/vaapi/gstvaapidisplaycache.c index e8c08ac4e9..f5c6069a77 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplaycache.c +++ b/gst-libs/gst/vaapi/gstvaapidisplaycache.c @@ -37,6 +37,7 @@ struct _CacheEntry struct _GstVaapiDisplayCache { GstVaapiMiniObject parent_instance; + GRecMutex mutex; GList *list; }; @@ -164,13 +165,13 @@ gst_vaapi_display_cache_finalize (GstVaapiDisplayCache * cache) { GList *l; - if (!cache->list) - return; - - for (l = cache->list; l != NULL; l = l->next) - cache_entry_free (l->data); - g_list_free (cache->list); - cache->list = NULL; + if (cache->list) { + for (l = cache->list; l != NULL; l = l->next) + cache_entry_free (l->data); + g_list_free (cache->list); + cache->list = NULL; + } + g_rec_mutex_clear (&cache->mutex); } static const GstVaapiMiniObjectClass * @@ -193,8 +194,44 @@ gst_vaapi_display_cache_class (void) GstVaapiDisplayCache * gst_vaapi_display_cache_new (void) { - return (GstVaapiDisplayCache *) - gst_vaapi_mini_object_new0 (gst_vaapi_display_cache_class ()); + GstVaapiDisplayCache *cache; + + cache = (GstVaapiDisplayCache *) + gst_vaapi_mini_object_new (gst_vaapi_display_cache_class ()); + if (!cache) + return NULL; + + g_rec_mutex_init (&cache->mutex); + cache->list = NULL; + return cache; +} + +/** + * gst_vaapi_display_cache_lock: + * @cache: the #GstVaapiDisplayCache + * + * Locks the display cache @cache. + */ +void +gst_vaapi_display_cache_lock (GstVaapiDisplayCache * cache) +{ + g_return_if_fail (cache != NULL); + + g_rec_mutex_lock (&cache->mutex); +} + +/** + * gst_vaapi_display_cache_unlock: + * @cache: the #GstVaapiDisplayCache + * + * Unlocks the display cache @cache. + */ +void +gst_vaapi_display_cache_unlock (GstVaapiDisplayCache * cache) +{ + g_return_if_fail (cache != NULL); + + g_rec_mutex_unlock (&cache->mutex); } /** diff --git a/gst-libs/gst/vaapi/gstvaapidisplaycache.h b/gst-libs/gst/vaapi/gstvaapidisplaycache.h index f7274327f1..9d0abb7762 100644 --- a/gst-libs/gst/vaapi/gstvaapidisplaycache.h +++ b/gst-libs/gst/vaapi/gstvaapidisplaycache.h @@ -42,6 +42,14 @@ gst_vaapi_display_cache_new (void); gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) (old_cache_ptr), \ GST_VAAPI_MINI_OBJECT (new_cache)) +G_GNUC_INTERNAL +void +gst_vaapi_display_cache_lock (GstVaapiDisplayCache * cache); + +G_GNUC_INTERNAL +void +gst_vaapi_display_cache_unlock (GstVaapiDisplayCache * cache); + G_GNUC_INTERNAL gboolean gst_vaapi_display_cache_is_empty (GstVaapiDisplayCache * cache);