libs: use glib >= 2.32 semantics for mutexes.

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.
This commit is contained in:
Gwenole Beauchesne 2012-12-17 10:10:55 +01:00
parent 1d669a3e12
commit 97c3b2ddff
4 changed files with 20 additions and 23 deletions

View file

@ -725,7 +725,7 @@ gst_vaapi_display_lock_default(GstVaapiDisplay *display)
if (priv->parent) if (priv->parent)
priv = priv->parent->priv; priv = priv->parent->priv;
g_static_rec_mutex_lock(&priv->mutex); g_rec_mutex_lock(&priv->mutex);
} }
static void static void
@ -735,7 +735,7 @@ gst_vaapi_display_unlock_default(GstVaapiDisplay *display)
if (priv->parent) if (priv->parent)
priv = priv->parent->priv; priv = priv->parent->priv;
g_static_rec_mutex_unlock(&priv->mutex); g_rec_mutex_unlock(&priv->mutex);
} }
static void static void
@ -745,7 +745,7 @@ gst_vaapi_display_finalize(GObject *object)
gst_vaapi_display_destroy(display); 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); G_OBJECT_CLASS(gst_vaapi_display_parent_class)->finalize(object);
} }
@ -998,7 +998,7 @@ gst_vaapi_display_init(GstVaapiDisplay *display)
priv->properties = NULL; priv->properties = NULL;
priv->create_display = TRUE; priv->create_display = TRUE;
g_static_rec_mutex_init(&priv->mutex); g_rec_mutex_init(&priv->mutex);
} }
/** /**

View file

@ -73,7 +73,7 @@ G_BEGIN_DECLS
*/ */
struct _GstVaapiDisplayPrivate { struct _GstVaapiDisplayPrivate {
GstVaapiDisplay *parent; GstVaapiDisplay *parent;
GStaticRecMutex mutex; GRecMutex mutex;
GstVaapiDisplayType display_type; GstVaapiDisplayType display_type;
VADisplay display; VADisplay display;
guint width; guint width;

View file

@ -33,7 +33,7 @@ struct _CacheEntry {
}; };
struct _GstVaapiDisplayCache { struct _GstVaapiDisplayCache {
GStaticMutex mutex; GMutex mutex;
GList *list; GList *list;
}; };
@ -86,14 +86,14 @@ error:
#define CACHE_LOOKUP(cache, res, prop, comp_func, comp_data, user_data) do { \ #define CACHE_LOOKUP(cache, res, prop, comp_func, comp_data, user_data) do { \
GList *l; \ GList *l; \
\ \
g_static_mutex_lock(&(cache)->mutex); \ g_mutex_lock(&(cache)->mutex); \
for (l = (cache)->list; l != NULL; l = l->next) { \ for (l = (cache)->list; l != NULL; l = l->next) { \
GstVaapiDisplayInfo * const info = \ GstVaapiDisplayInfo * const info = \
&((CacheEntry *)l->data)->info; \ &((CacheEntry *)l->data)->info; \
if (comp_func(info->prop, comp_data, user_data)) \ if (comp_func(info->prop, comp_data, user_data)) \
break; \ break; \
} \ } \
g_static_mutex_unlock(&(cache)->mutex); \ g_mutex_unlock(&(cache)->mutex); \
res = l; \ res = l; \
} while (0) } while (0)
@ -146,7 +146,7 @@ gst_vaapi_display_cache_new(void)
if (!cache) if (!cache)
return NULL; return NULL;
g_static_mutex_init(&cache->mutex); g_mutex_init(&cache->mutex);
return cache; return cache;
} }
@ -170,7 +170,7 @@ gst_vaapi_display_cache_free(GstVaapiDisplayCache *cache)
g_list_free(cache->list); g_list_free(cache->list);
cache->list = NULL; cache->list = NULL;
} }
g_static_mutex_free(&cache->mutex); g_mutex_clear(&cache->mutex);
g_slice_free(GstVaapiDisplayCache, cache); 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_return_val_if_fail(cache != NULL, 0);
g_static_mutex_lock(&cache->mutex); g_mutex_lock(&cache->mutex);
size = g_list_length(cache->list); size = g_list_length(cache->list);
g_static_mutex_unlock(&cache->mutex); g_mutex_unlock(&cache->mutex);
return size; return size;
} }
@ -220,9 +220,9 @@ gst_vaapi_display_cache_add(
if (!entry) if (!entry)
return FALSE; return FALSE;
g_static_mutex_lock(&cache->mutex); g_mutex_lock(&cache->mutex);
cache->list = g_list_prepend(cache->list, entry); cache->list = g_list_prepend(cache->list, entry);
g_static_mutex_unlock(&cache->mutex); g_mutex_unlock(&cache->mutex);
return TRUE; return TRUE;
} }
@ -246,9 +246,9 @@ gst_vaapi_display_cache_remove(
return; return;
cache_entry_free(m->data); 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); cache->list = g_list_delete_link(cache->list, m);
g_static_mutex_unlock(&cache->mutex); g_mutex_unlock(&cache->mutex);
} }
/** /**

View file

@ -741,16 +741,13 @@ gl_init_vtable(void)
GLVTable * GLVTable *
gl_get_vtable(void) gl_get_vtable(void)
{ {
static GStaticMutex mutex = G_STATIC_MUTEX_INIT; static gsize gl_vtable_init = FALSE;
static gboolean gl_vtable_init = TRUE;
static GLVTable *gl_vtable = NULL; static GLVTable *gl_vtable = NULL;
g_static_mutex_lock(&mutex); if (g_once_init_enter(&gl_vtable_init)) {
if (gl_vtable_init) { gl_vtable = gl_init_vtable();
gl_vtable_init = FALSE; g_once_init_leave(&gl_vtable_init, TRUE);
gl_vtable = gl_init_vtable();
} }
g_static_mutex_unlock(&mutex);
return gl_vtable; return gl_vtable;
} }