[libchamplain] Add a RWLock to protect the state of the MemphisRenderer



commit 3b4c286804d82593eafcc24cf63e894cee30188e
Author: Simon Wenner <simon wenner ch>
Date:   Thu Jun 25 16:13:37 2009 +0200

    Add a RWLock to protect the state of the MemphisRenderer

 champlain/champlain-memphis-map-source.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/champlain/champlain-memphis-map-source.c b/champlain/champlain-memphis-map-source.c
index 39c15e0..722cd09 100644
--- a/champlain/champlain-memphis-map-source.c
+++ b/champlain/champlain-memphis-map-source.c
@@ -56,9 +56,11 @@ struct _ChamplainMemphisMapSourcePrivate {
   MemphisRuleSet *rules;
   MemphisRenderer *renderer;
   GThreadPool *thpool;
-  //GStaticRWLock rwlock;
 };
 
+/* lock to protect the renderer state while rendering */
+GStaticRWLock MemphisLock = G_STATIC_RW_LOCK_INIT;
+
 static void
 champlain_memphis_map_source_get_property (GObject *object, guint property_id,
                               GValue *value, GParamSpec *pspec)
@@ -195,7 +197,9 @@ memphis_worker_thread (gpointer data, gpointer user_data)
 
   DEBUG ("Draw Tile (%d, %d, %d)", x, y, z);
 
+  g_static_rw_lock_reader_lock (&MemphisLock);
   memphis_renderer_draw_tile (renderer, cr, x, y, z);
+  g_static_rw_lock_reader_unlock (&MemphisLock);
   cairo_destroy (cr);
 
   tdata = g_new (TileData, 1);
@@ -311,10 +315,12 @@ champlain_memphis_map_source_load_rules (
 
   ChamplainMemphisMapSourcePrivate *priv = GET_PRIVATE(self);
 
+  g_static_rw_lock_writer_lock (&MemphisLock);
   if (rules_path)
     memphis_rule_set_load_from_file (priv->rules, rules_path);
   else
     memphis_rule_set_load_from_file (priv->rules, DEFAULT_RULES_PATH);
+  g_static_rw_lock_writer_unlock (&MemphisLock);
 }
 
 void
@@ -329,9 +335,11 @@ champlain_memphis_map_source_set_map_data_source (
   MemphisMap *map;
 
   priv->map_data_source = map_data_source;
-
   map = champlain_map_data_source_get_map_data (priv->map_data_source);
+
+  g_static_rw_lock_writer_lock (&MemphisLock);
   memphis_renderer_set_map (priv->renderer, map);
+  g_static_rw_lock_writer_unlock (&MemphisLock);
 }
 
 ChamplainMapDataSource *



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