[Xfce4-commits] <xfconf:master> Use new glib 2.32 mutex api.

Nick Schermer noreply at xfce.org
Wed Nov 7 18:26:01 CET 2012


Updating branch refs/heads/master
         to 59a09ced038e55715796f36ba56caa4421d8a1bf (commit)
       from 8d750317a679ef79ddac324972603b74df4782fb (commit)

commit 59a09ced038e55715796f36ba56caa4421d8a1bf
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Nov 6 19:26:16 2012 +0100

    Use new glib 2.32 mutex api.

 xfconf/xfconf-cache.c |   70 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/xfconf/xfconf-cache.c b/xfconf/xfconf-cache.c
index 1dc2e1f..a502ff1 100644
--- a/xfconf/xfconf-cache.c
+++ b/xfconf/xfconf-cache.c
@@ -47,10 +47,16 @@
 
 #define ALIGN_VAL(val, align)  ( ((val) + ((align) -1)) & ~((align) - 1) )
 
-static void xfconf_cache_mutex_lock(GStaticMutex *mtx) __attribute__((noinline));
-static void xfconf_cache_mutex_lock(GStaticMutex *mtx) { g_static_mutex_lock(mtx); }
-static void xfconf_cache_mutex_unlock(GStaticMutex *mtx) __attribute__((noinline));
-static void xfconf_cache_mutex_unlock(GStaticMutex *mtx) { g_static_mutex_unlock(mtx); }
+
+
+#if GLIB_CHECK_VERSION (2, 32, 0)
+#define xfconf_cache_mutex_lock(cache)   g_mutex_lock (&(cache)->cache_lock)
+#define xfconf_cache_mutex_unlock(cache) g_mutex_unlock (&(cache)->cache_lock)
+#else
+#define xfconf_cache_mutex_lock(cache)   g_mutex_lock ((cache)->cache_lock)
+#define xfconf_cache_mutex_unlock(cache) g_mutex_unlock ((cache)->cache_lock)
+#endif
+
 
 
 /**************** XfconfCacheItem ****************/
@@ -210,7 +216,11 @@ struct _XfconfCache
     GHashTable *pending_calls;
     GHashTable *old_properties;
 
-    GStaticMutex cache_lock;
+#if GLIB_CHECK_VERSION (2, 32, 0)
+    GMutex cache_lock;
+#else
+    GMutex *cache_lock;
+#endif
 };
 
 typedef struct _XfconfCacheClass
@@ -347,7 +357,11 @@ xfconf_cache_init(XfconfCache *cache)
     cache->old_properties = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                   NULL, NULL);
 
-    g_static_mutex_init(&cache->cache_lock);
+#if GLIB_CHECK_VERSION (2, 32, 0)
+    g_mutex_init (&cache->cache_lock);
+#else
+    cache->cache_lock = g_mutex_new ();
+#endif
 }
 
 static void
@@ -433,7 +447,9 @@ xfconf_cache_finalize(GObject *obj)
     g_tree_destroy(cache->properties);
     g_hash_table_destroy(cache->old_properties);
 
-    g_static_mutex_free(&cache->cache_lock);
+#if !GLIB_CHECK_VERSION (2, 32, 0)
+    g_mutex_free (cache->cache_lock);
+#endif
 
     G_OBJECT_CLASS(xfconf_cache_parent_class)->finalize(obj);
 }
@@ -508,7 +524,7 @@ xfconf_cache_set_property_reply_handler(DBusGProxy *proxy,
     if(!cache->pending_calls)
         return;
 
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
 
     old_item = g_hash_table_lookup(cache->pending_calls, call);
     if(G_UNLIKELY(!old_item)) {
@@ -547,12 +563,12 @@ xfconf_cache_set_property_reply_handler(DBusGProxy *proxy,
         }
 
         /* we need to drop the lock when running the signal handlers */
-        xfconf_cache_mutex_unlock(&cache->cache_lock);
+        xfconf_cache_mutex_unlock(cache);
         g_signal_emit(G_OBJECT(cache), signals[SIG_PROPERTY_CHANGED],
                       g_quark_from_string(old_item->property),
                       cache->channel_name, old_item->property,
                       item ? item->value : &empty_val);
-        xfconf_cache_mutex_lock(&cache->cache_lock);
+        xfconf_cache_mutex_lock(cache);
     }
 
     /* we handled the call, so set it to %NULL */
@@ -561,7 +577,7 @@ xfconf_cache_set_property_reply_handler(DBusGProxy *proxy,
     if(old_item)
         xfconf_cache_old_item_free(old_item);
 out:
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 }
 
 
@@ -576,7 +592,7 @@ xfconf_cache_reset_property_reply_handler(DBusGProxy *proxy,
     XfconfCacheOldItem *old_item;
     GError *error = NULL;
 
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
 
     old_item = g_hash_table_lookup(cache->pending_calls, call);
     if(G_UNLIKELY(!old_item)) {
@@ -594,7 +610,7 @@ out:
     if(old_item)
         g_hash_table_remove(cache->pending_calls, old_item->call);
 
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 }
 #endif
 
@@ -634,7 +650,7 @@ xfconf_cache_prefetch(XfconfCache *cache,
 
     g_return_val_if_fail(g_tree_nnodes(cache->properties) == 0, FALSE);
 
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
 
     if(xfconf_client_get_all_properties(proxy, cache->channel_name,
                                         property_base ? property_base : "/",
@@ -647,7 +663,7 @@ xfconf_cache_prefetch(XfconfCache *cache,
     } else
         g_propagate_error(error, tmp_error);
 
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 
     return ret;
 }
@@ -710,9 +726,9 @@ xfconf_cache_lookup(XfconfCache *cache,
     g_return_val_if_fail(XFCONF_IS_CACHE(cache) && property
                          && (!error || !*error), FALSE);
 
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
     ret = xfconf_cache_lookup_locked(cache, property, value, error);
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 
     return ret;
 }
@@ -727,7 +743,7 @@ xfconf_cache_set(XfconfCache *cache,
     XfconfCacheItem *item = NULL;
     XfconfCacheOldItem *old_item = NULL;
 
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
 
     item = g_tree_lookup(cache->properties, property);
     if(!item) {
@@ -756,7 +772,7 @@ xfconf_cache_set(XfconfCache *cache,
             {
                 /* this is bad... */
                 g_propagate_error(error, tmp_error);
-                xfconf_cache_mutex_unlock(&cache->cache_lock);
+                xfconf_cache_mutex_unlock(cache);
                 return FALSE;
             }
 
@@ -771,7 +787,7 @@ xfconf_cache_set(XfconfCache *cache,
     if(item) {
         /* if the value isn't changing, there's no reason to continue */
         if(_xfconf_gvalue_is_equal(item->value, value)) {
-            xfconf_cache_mutex_unlock(&cache->cache_lock);
+            xfconf_cache_mutex_unlock(cache);
             return TRUE;
         }
     }
@@ -814,7 +830,7 @@ xfconf_cache_set(XfconfCache *cache,
         g_tree_insert(cache->properties, g_strdup(property), item);
     }
 
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 
     g_signal_emit(G_OBJECT(cache), signals[SIG_PROPERTY_CHANGED], 0,
                   cache->channel_name, property, value);
@@ -855,7 +871,7 @@ xfconf_cache_reset(XfconfCache *cache,
     XfconfCacheOldItem *old_item = NULL;
 #endif
 
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
 
 #if 0
     /* it's not really feasible here to look up all the old/new values
@@ -919,7 +935,7 @@ xfconf_cache_reset(XfconfCache *cache,
     }
 #endif
 
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 
     return ret;
 }
@@ -929,10 +945,10 @@ void
 xfconf_cache_set_max_entries(XfconfCache *cache,
                              gint max_entries)
 {
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
     cache->max_entries = max_entries;
     /* TODO: check tree for eviction */
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 }
 
 gint
@@ -945,10 +961,10 @@ void
 xfconf_cache_set_max_age(XfconfCache *cache,
                          gint max_age)
 {
-    xfconf_cache_mutex_lock(&cache->cache_lock);
+    xfconf_cache_mutex_lock(cache);
     cache->max_age = max_age;
     /* TODO: check tree for eviction */
-    xfconf_cache_mutex_unlock(&cache->cache_lock);
+    xfconf_cache_mutex_unlock(cache);
 }
 
 gint


More information about the Xfce4-commits mailing list