[libchamplain] Define g_rw_lock_* on glib <2.32 versions and use these functions for locking



commit fd5c32596a85a4d93992b34f32deb26bf443634c
Author: Jiří Techet <techet gmail com>
Date:   Mon Apr 8 23:25:14 2013 +0200

    Define g_rw_lock_* on glib <2.32 versions and use these functions for locking

 champlain/champlain-memphis-renderer.c |   57 ++++++++++++++++++--------------
 1 files changed, 32 insertions(+), 25 deletions(-)
---
diff --git a/champlain/champlain-memphis-renderer.c b/champlain/champlain-memphis-renderer.c
index c8a715a..15ed6d0 100644
--- a/champlain/champlain-memphis-renderer.c
+++ b/champlain/champlain-memphis-renderer.c
@@ -106,8 +106,15 @@ struct _WorkerThreadData
 };
 
 /* lock to protect the renderer state while rendering */
-GStaticRWLock MemphisLock = G_STATIC_RW_LOCK_INIT;
-
+#if GLIB_CHECK_VERSION(2,32,0)
+  static GRWLock MemphisLock;
+#else
+  GStaticRWLock MemphisLock = G_STATIC_RW_LOCK_INIT;
+  #define g_rw_lock_reader_lock(l)   g_static_rw_lock_reader_lock (l)
+  #define g_rw_lock_reader_unlock(l) g_static_rw_lock_reader_unlock (l)
+  #define g_rw_lock_writer_lock(l)   g_static_rw_lock_writer_lock (l)
+  #define g_rw_lock_writer_unlock(l) g_static_rw_lock_writer_unlock (l)
+#endif
 
 static void memphis_worker_thread (gpointer data,
     gpointer user_data);
@@ -375,9 +382,9 @@ memphis_worker_thread (gpointer worker_data,
 
   data->cst = NULL;
 
-  g_static_rw_lock_reader_lock (&MemphisLock);
+  g_rw_lock_reader_lock (&MemphisLock);
   has_data = memphis_renderer_tile_has_data (renderer->priv->renderer, data->x, data->y, data->z);
-  g_static_rw_lock_reader_unlock (&MemphisLock);
+  g_rw_lock_reader_unlock (&MemphisLock);
 
   if (has_data)
     {
@@ -389,9 +396,9 @@ memphis_worker_thread (gpointer worker_data,
 
       DEBUG ("Draw Tile (%d, %d, %d)", data->x, data->y, data->z);
 
-      g_static_rw_lock_reader_lock (&MemphisLock);
+      g_rw_lock_reader_lock (&MemphisLock);
       memphis_renderer_draw_tile (renderer->priv->renderer, cr, data->x, data->y, data->z);
-      g_static_rw_lock_reader_unlock (&MemphisLock);
+      g_rw_lock_reader_unlock (&MemphisLock);
 
       cairo_destroy (cr);
     }
@@ -460,9 +467,9 @@ set_data (ChamplainRenderer *renderer,
       return;
     }
 
-  g_static_rw_lock_writer_lock (&MemphisLock);
+  g_rw_lock_writer_lock (&MemphisLock);
   memphis_renderer_set_map (priv->renderer, map);
-  g_static_rw_lock_writer_unlock (&MemphisLock);
+  g_rw_lock_writer_unlock (&MemphisLock);
 
   bbox = champlain_bounding_box_new ();
 
@@ -499,7 +506,7 @@ champlain_memphis_renderer_load_rules (
       return;
     }
 
-  g_static_rw_lock_writer_lock (&MemphisLock);
+  g_rw_lock_writer_lock (&MemphisLock);
   if (rules_path)
     {
       memphis_rule_set_load_from_file (priv->rules, rules_path, &err);
@@ -508,7 +515,7 @@ champlain_memphis_renderer_load_rules (
           g_critical ("Can't load rules file: \"%s\"", err->message);
           memphis_rule_set_load_from_data (priv->rules, default_rules,
               strlen (default_rules), NULL);
-          g_static_rw_lock_writer_unlock (&MemphisLock);
+          g_rw_lock_writer_unlock (&MemphisLock);
           g_error_free (err);
           return;
         }
@@ -517,7 +524,7 @@ champlain_memphis_renderer_load_rules (
     memphis_rule_set_load_from_data (priv->rules, default_rules,
         strlen (default_rules), NULL);
 
-  g_static_rw_lock_writer_unlock (&MemphisLock);
+  g_rw_lock_writer_unlock (&MemphisLock);
 }
 
 
@@ -541,9 +548,9 @@ champlain_memphis_renderer_get_background_color (
   ClutterColor color;
   guint8 r, b, g, a;
 
-  g_static_rw_lock_reader_lock (&MemphisLock);
+  g_rw_lock_reader_lock (&MemphisLock);
   memphis_rule_set_get_bg_color (renderer->priv->rules, &r, &g, &b, &a);
-  g_static_rw_lock_reader_unlock (&MemphisLock);
+  g_rw_lock_reader_unlock (&MemphisLock);
 
   color.red = r;
   color.green = g;
@@ -569,10 +576,10 @@ champlain_memphis_renderer_set_background_color (
 {
   g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));
 
-  g_static_rw_lock_writer_lock (&MemphisLock);
+  g_rw_lock_writer_lock (&MemphisLock);
   memphis_rule_set_set_bg_color (renderer->priv->rules, color->red,
       color->green, color->blue, color->alpha);
-  g_static_rw_lock_writer_unlock (&MemphisLock);
+  g_rw_lock_writer_unlock (&MemphisLock);
 }
 
 
@@ -593,9 +600,9 @@ champlain_memphis_renderer_set_rule (ChamplainMemphisRenderer *renderer,
   g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer) &&
       MEMPHIS_RULE (rule));
 
-  g_static_rw_lock_writer_lock (&MemphisLock);
+  g_rw_lock_writer_lock (&MemphisLock);
   memphis_rule_set_set_rule (renderer->priv->rules, (MemphisRule *) rule);
-  g_static_rw_lock_writer_unlock (&MemphisLock);
+  g_rw_lock_writer_unlock (&MemphisLock);
 }
 
 
@@ -619,9 +626,9 @@ champlain_memphis_renderer_get_rule (ChamplainMemphisRenderer *renderer,
 
   MemphisRule *rule;
 
-  g_static_rw_lock_reader_lock (&MemphisLock);
+  g_rw_lock_reader_lock (&MemphisLock);
   rule = memphis_rule_set_get_rule (renderer->priv->rules, id);
-  g_static_rw_lock_reader_unlock (&MemphisLock);
+  g_rw_lock_reader_unlock (&MemphisLock);
 
   return (ChamplainMemphisRule *) rule;
 }
@@ -647,9 +654,9 @@ champlain_memphis_renderer_get_rule_ids (ChamplainMemphisRenderer *renderer)
 
   GList *list;
 
-  g_static_rw_lock_reader_lock (&MemphisLock);
+  g_rw_lock_reader_lock (&MemphisLock);
   list = memphis_rule_set_get_rule_ids (renderer->priv->rules);
-  g_static_rw_lock_reader_unlock (&MemphisLock);
+  g_rw_lock_reader_unlock (&MemphisLock);
 
   return list;
 }
@@ -671,9 +678,9 @@ champlain_memphis_renderer_remove_rule (
 {
   g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));
 
-  g_static_rw_lock_writer_lock (&MemphisLock);
+  g_rw_lock_writer_lock (&MemphisLock);
   memphis_rule_set_remove_rule (renderer->priv->rules, id);
-  g_static_rw_lock_writer_unlock (&MemphisLock);
+  g_rw_lock_writer_unlock (&MemphisLock);
 }
 
 
@@ -696,9 +703,9 @@ champlain_memphis_renderer_set_tile_size (ChamplainMemphisRenderer *renderer,
 
   renderer->priv->tile_size = size;
 
-  g_static_rw_lock_writer_lock (&MemphisLock);
+  g_rw_lock_writer_lock (&MemphisLock);
   memphis_renderer_set_resolution (priv->renderer, size);
-  g_static_rw_lock_writer_unlock (&MemphisLock);
+  g_rw_lock_writer_unlock (&MemphisLock);
 
   g_object_notify (G_OBJECT (renderer), "tile-size");
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]