libs: use glib >= 2.32 semantics for mutexes.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 17 Dec 2012 09:10:55 +0000 (10:10 +0100)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 17 Dec 2012 13:56:11 +0000 (14:56 +0100)
Use glib >= 2.32 semantics for GMutex and GRecMutex wrt. initialization
and termination. Basically, the new mutex objects can be used as static
mutex objects from the deprecated APIs, e.g. GStaticMutex and GStaticRecMutex.

gst-libs/gst/vaapi/gstvaapidisplay.c
gst-libs/gst/vaapi/gstvaapidisplay_priv.h
gst-libs/gst/vaapi/gstvaapidisplaycache.c
gst-libs/gst/vaapi/gstvaapiutils_glx.c

index 40ac5a6..35a3d57 100644 (file)
@@ -725,7 +725,7 @@ gst_vaapi_display_lock_default(GstVaapiDisplay *display)
 
     if (priv->parent)
         priv = priv->parent->priv;
-    g_static_rec_mutex_lock(&priv->mutex);
+    g_rec_mutex_lock(&priv->mutex);
 }
 
 static void
@@ -735,7 +735,7 @@ gst_vaapi_display_unlock_default(GstVaapiDisplay *display)
 
     if (priv->parent)
         priv = priv->parent->priv;
-    g_static_rec_mutex_unlock(&priv->mutex);
+    g_rec_mutex_unlock(&priv->mutex);
 }
 
 static void
@@ -745,7 +745,7 @@ gst_vaapi_display_finalize(GObject *object)
 
     gst_vaapi_display_destroy(display);
 
-    g_static_rec_mutex_free(&display->priv->mutex);
+    g_rec_mutex_clear(&display->priv->mutex);
 
     G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
 }
@@ -998,7 +998,7 @@ gst_vaapi_display_init(GstVaapiDisplay *display)
     priv->properties            = NULL;
     priv->create_display        = TRUE;
 
-    g_static_rec_mutex_init(&priv->mutex);
+    g_rec_mutex_init(&priv->mutex);
 }
 
 /**
index ac0555e..cb5302b 100644 (file)
@@ -73,7 +73,7 @@ G_BEGIN_DECLS
  */
 struct _GstVaapiDisplayPrivate {
     GstVaapiDisplay    *parent;
-    GStaticRecMutex     mutex;
+    GRecMutex           mutex;
     GstVaapiDisplayType display_type;
     VADisplay           display;
     guint               width;
index 0e6ef36..5f5ae8d 100644 (file)
@@ -33,7 +33,7 @@ struct _CacheEntry {
 };
 
 struct _GstVaapiDisplayCache {
-    GStaticMutex        mutex;
+    GMutex              mutex;
     GList              *list;
 };
 
@@ -86,14 +86,14 @@ error:
 #define CACHE_LOOKUP(cache, res, prop, comp_func, comp_data, user_data) do { \
         GList *l;                                                       \
                                                                         \
-        g_static_mutex_lock(&(cache)->mutex);                           \
+        g_mutex_lock(&(cache)->mutex);                                  \
         for (l = (cache)->list; l != NULL; l = l->next) {               \
             GstVaapiDisplayInfo * const info =                          \
                 &((CacheEntry *)l->data)->info;                         \
             if (comp_func(info->prop, comp_data, user_data))            \
                 break;                                                  \
         }                                                               \
-        g_static_mutex_unlock(&(cache)->mutex);                         \
+        g_mutex_unlock(&(cache)->mutex);                                \
         res = l;                                                        \
     } while (0)
 
@@ -146,7 +146,7 @@ gst_vaapi_display_cache_new(void)
     if (!cache)
         return NULL;
 
-    g_static_mutex_init(&cache->mutex);
+    g_mutex_init(&cache->mutex);
     return cache;
 }
 
@@ -170,7 +170,7 @@ gst_vaapi_display_cache_free(GstVaapiDisplayCache *cache)
         g_list_free(cache->list);
         cache->list = NULL;
     }
-    g_static_mutex_free(&cache->mutex);
+    g_mutex_clear(&cache->mutex);
     g_slice_free(GstVaapiDisplayCache, cache);
 }
 
@@ -189,9 +189,9 @@ gst_vaapi_display_cache_get_size(GstVaapiDisplayCache *cache)
 
     g_return_val_if_fail(cache != NULL, 0);
 
-    g_static_mutex_lock(&cache->mutex);
+    g_mutex_lock(&cache->mutex);
     size = g_list_length(cache->list);
-    g_static_mutex_unlock(&cache->mutex);
+    g_mutex_unlock(&cache->mutex);
     return size;
 }
 
@@ -220,9 +220,9 @@ gst_vaapi_display_cache_add(
     if (!entry)
         return FALSE;
 
-    g_static_mutex_lock(&cache->mutex);
+    g_mutex_lock(&cache->mutex);
     cache->list = g_list_prepend(cache->list, entry);
-    g_static_mutex_unlock(&cache->mutex);
+    g_mutex_unlock(&cache->mutex);
     return TRUE;
 }
 
@@ -246,9 +246,9 @@ gst_vaapi_display_cache_remove(
         return;
 
     cache_entry_free(m->data);
-    g_static_mutex_lock(&cache->mutex);
+    g_mutex_lock(&cache->mutex);
     cache->list = g_list_delete_link(cache->list, m);
-    g_static_mutex_unlock(&cache->mutex);
+    g_mutex_unlock(&cache->mutex);
 }
 
 /**
index 9a742ca..4788c95 100644 (file)
@@ -741,16 +741,13 @@ gl_init_vtable(void)
 GLVTable *
 gl_get_vtable(void)
 {
-    static GStaticMutex mutex          = G_STATIC_MUTEX_INIT;
-    static gboolean     gl_vtable_init = TRUE;
+    static gsize        gl_vtable_init = FALSE;
     static GLVTable    *gl_vtable      = NULL;
 
-    g_static_mutex_lock(&mutex);
-    if (gl_vtable_init) {
-        gl_vtable_init = FALSE;
-        gl_vtable      = gl_init_vtable();
+    if (g_once_init_enter(&gl_vtable_init)) {
+        gl_vtable = gl_init_vtable();
+        g_once_init_leave(&gl_vtable_init, TRUE);
     }
-    g_static_mutex_unlock(&mutex);
     return gl_vtable;
 }