]> git.street.me.uk Git - andy/viking.git/commitdiff
Added mutex to protect map pixbuf cache from being corrupted.
authorQuy Tonthat <qtonthat@gmail.com>
Fri, 18 Jan 2008 04:36:12 +0000 (04:36 +0000)
committerQuy Tonthat <qtonthat@gmail.com>
Fri, 18 Jan 2008 04:36:12 +0000 (04:36 +0000)
Since the ring list and the hash and other house keeping data for the
pixbuf cache are modified by (map download) threads, there are potentional
problems of data corruption. A mutex was added to address the problem.

Signed-off-by: Quy Tonthat <qtonthat@gmail.com>
ChangeLog
src/mapcache.c

index ac0bc76d3d2a6f5f150ad74a6e81aabd177bd914..9b14096b6aff57d96c691afed25f2c6b969a9413 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-1-18
+Qut Tonthat <qtonthat@gmail.com>:
+       * Fix a crash bug in mapcache reported by Jocelyn <jocelyn.jaubert@gmail.com>
+       * Added mutex to protect mapcache from being corrupted by threads.
+
 2008-01-04:
 Alex Foobarian <foobarian@gmail.com>:
        * Tuned the v-t diagram drawing
index 3dd8023a118d7146d9f89cee08a00d44f7584aa5..ffaa3528bcfbfd6fe632f3b20def8f04b5877fd2 100644 (file)
@@ -40,11 +40,14 @@ static guint32 queue_size = 0;
 
 static GHashTable *cache = NULL;
 
+static GMutex *mc_mutex = NULL;
+
 #define HASHKEY_FORMAT_STRING "%d-%d-%d-%d-%d-%d-%.3f-%.3f"
 #define HASHKEY_FORMAT_STRING_NOSHRINK_NOR_ALPHA "%d-%d-%d-%d-%d-"
 
 void a_mapcache_init ()
 {
+  mc_mutex = g_mutex_new();
   cache = g_hash_table_new_full ( g_str_hash, g_str_equal, g_free, g_object_unref );
 }
 
@@ -106,6 +109,7 @@ void a_mapcache_add ( GdkPixbuf *pixbuf, gint x, gint y, gint z, guint8 type, gu
   gchar *key = g_strdup_printf ( HASHKEY_FORMAT_STRING, x, y, z, type, zoom, alpha, xshrinkfactor, yshrinkfactor );
   static int tmp = 0;
 
+  g_mutex_lock(mc_mutex);
   cache_add(key, pixbuf);
 
   if ( queue_size > VIK_CONFIG_MAPCACHE_SIZE ) {
@@ -123,6 +127,7 @@ void a_mapcache_add ( GdkPixbuf *pixbuf, gint x, gint y, gint z, guint8 type, gu
     list_add_entry ( key );
     /* business as usual */
   }
+  g_mutex_unlock(mc_mutex);
 
   if ( (++tmp == 100 ))  { g_print("DEBUG: queue count=%d %u\n", queue_count, queue_size ); tmp=0; }
 }
@@ -147,6 +152,7 @@ void a_mapcache_remove_all_shrinkfactors ( gint x, gint y, gint z, guint8 type,
   g_snprintf ( key, sizeof(key), HASHKEY_FORMAT_STRING_NOSHRINK_NOR_ALPHA, x, y, z, type, zoom );
   len = strlen(key);
 
+  g_mutex_lock(mc_mutex);
   /* TODO: check logic here */
   do {
     tmp = loop->next;
@@ -170,6 +176,7 @@ void a_mapcache_remove_all_shrinkfactors ( gint x, gint y, gint z, guint8 type,
 
   /* loop thru list, looking for the one, compare first whatever chars */
   cache_remove(key);
+  g_mutex_unlock(mc_mutex);
 }
 
 void a_mapcache_uninit ()