evolution-data-server r8855 - in branches/gnome-2-22/servers/exchange: . lib



Author: mcrha
Date: Mon May 26 17:56:11 2008
New Revision: 8855
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8855&view=rev

Log:
2008-05-26  Milan Crha  <mcrha redhat com>

	** Fix for bug #473658

	* lib/e2k-properties.c: (copy_prop), (properties_free_cb),
	(get_propinfo), (foreach_callback), (foreach_namespace_callback),
	(e2k_prop_namespace_name), (e2k_prop_namespace_abbrev): Added locks
	to guard global variables 'known_properties' and 'namespaces'.



Modified:
   branches/gnome-2-22/servers/exchange/ChangeLog
   branches/gnome-2-22/servers/exchange/lib/e2k-properties.c

Modified: branches/gnome-2-22/servers/exchange/lib/e2k-properties.c
==============================================================================
--- branches/gnome-2-22/servers/exchange/lib/e2k-properties.c	(original)
+++ branches/gnome-2-22/servers/exchange/lib/e2k-properties.c	Mon May 26 17:56:11 2008
@@ -45,6 +45,7 @@
 } E2kPropInfo;
 
 static GHashTable *known_properties;
+static GStaticMutex known_properties_lock = G_STATIC_MUTEX_INIT;
 
 /**
  * e2k_properties_new:
@@ -73,7 +74,10 @@
 	gpointer value_copy;
 	E2kPropInfo *pi;
 
+	g_static_mutex_lock (&known_properties_lock);
 	pi = g_hash_table_lookup (known_properties, name);
+	g_static_mutex_unlock (&known_properties_lock);
+
 	switch (pi->type) {
 	case E2K_PROP_TYPE_BINARY_ARRAY:
 	{
@@ -198,7 +202,9 @@
 {
 	E2kPropInfo *pi;
 
+	g_static_mutex_lock (&known_properties_lock);
 	pi = g_hash_table_lookup (known_properties, key);
+	g_static_mutex_unlock (&known_properties_lock);
 	if (pi)
 		free_prop (pi, value);
 }
@@ -264,6 +270,7 @@
 {
 	E2kPropInfo *pi;
 
+	g_static_mutex_lock (&known_properties_lock);
 	if (!known_properties)
 		known_properties = g_hash_table_new (g_str_hash, g_str_equal);
 
@@ -271,6 +278,7 @@
 	if (pi) {
 		if (pi->type == E2K_PROP_TYPE_UNKNOWN)
 			pi->type = type;
+		g_static_mutex_unlock (&known_properties_lock);
 		return pi;
 	}
 
@@ -287,6 +295,8 @@
 
 	g_hash_table_insert (known_properties, pi->name, pi);
 
+	g_static_mutex_unlock (&known_properties_lock);
+
 	return pi;
 }
 
@@ -487,7 +497,9 @@
 	struct foreach_data *fd = data;
 	E2kPropInfo *pi;
 
+	g_static_mutex_lock (&known_properties_lock);
 	pi = g_hash_table_lookup (known_properties, key);
+	g_static_mutex_unlock (&known_properties_lock);
 	if (pi)
 		fd->callback (pi->name, pi->type, value, fd->user_data);
 }
@@ -556,7 +568,9 @@
 	E2kPropInfo *pi;
 	const char *name;
 
+	g_static_mutex_lock (&known_properties_lock);
 	pi = g_hash_table_lookup (known_properties, key);
+	g_static_mutex_unlock (&known_properties_lock);
 	if (!pi)
 		return;
 
@@ -627,7 +641,7 @@
 
 static GHashTable *namespaces;
 static int next_namespace = 'a';
-
+static GStaticMutex namespaces_lock = G_STATIC_MUTEX_INIT;
 
 static const char *
 get_div (const char *propname)
@@ -683,15 +697,19 @@
 	gpointer key, value;
 	char *name;
 
+	g_static_mutex_lock (&namespaces_lock);
 	if (!namespaces)
 		setup_namespaces ();
 
-	if (g_hash_table_lookup_extended (namespaces, prop, &key, &value))
+	if (g_hash_table_lookup_extended (namespaces, prop, &key, &value)) {
+		g_static_mutex_unlock (&namespaces_lock);
 		return key;
+	}
 
 	name = g_strndup (prop, div - prop + 1);
 	g_hash_table_insert (namespaces, name, GINT_TO_POINTER (next_namespace));
 	next_namespace++;
+	g_static_mutex_unlock (&namespaces_lock);
 	return name;
 }
 
@@ -709,17 +727,23 @@
 {
 	const char *div = get_div (prop);
 	gpointer key, value;
-	char *name;
+	char *name, res;
 
+	g_static_mutex_lock (&namespaces_lock);
 	if (!namespaces)
 		setup_namespaces ();
 
-	if (g_hash_table_lookup_extended (namespaces, prop, &key, &value))
+	if (g_hash_table_lookup_extended (namespaces, prop, &key, &value)) {
+		g_static_mutex_unlock (&namespaces_lock);
 		return GPOINTER_TO_INT (value);
+	}
 
 	name = g_strndup (prop, div - prop + 1);
 	g_hash_table_insert (namespaces, name, GINT_TO_POINTER (next_namespace));
-	return next_namespace++;
+	res = next_namespace++;
+	g_static_mutex_unlock (&namespaces_lock);
+
+	return res;
 }
 
 /**



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