From 66587d89a30adfd7251dfd586e6213f9e9c536a0 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 13 Dec 2001 20:38:11 +0000 Subject: Keep a name-to-type hash so that we can make sure that the type has not 2001-12-11 Jeffrey Stedfast * camel-object.c (camel_type_register): Keep a name-to-type hash so that we can make sure that the type has not yet been registered (prevents a race condition such as the one in bug #16559). * camel-service.c (camel_service_connect): Make sure that the connect_op is non-NULL before unregistering/unreffing it. svn path=/trunk/; revision=15021 --- camel/camel-object.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'camel/camel-object.c') diff --git a/camel/camel-object.c b/camel/camel-object.c index 6d8b301f80..776d22e038 100644 --- a/camel/camel-object.c +++ b/camel/camel-object.c @@ -123,6 +123,7 @@ G_LOCK_DEFINE_STATIC (refcount); static gboolean type_system_initialized = FALSE; static GHashTable *ctype_to_typeinfo = NULL; +static GHashTable *name_to_typeinfo = NULL; static const CamelType camel_object_type = 1; static CamelType cur_max_type = CAMEL_INVALID_TYPE; @@ -179,15 +180,15 @@ camel_type_init (void) camel_type_lock_up (); if (type_system_initialized) { - g_warning - ("camel_type_init: type system already initialized."); + g_warning ("camel_type_init: type system already initialized."); camel_type_lock_down (); return; } type_system_initialized = TRUE; ctype_to_typeinfo = g_hash_table_new (g_direct_hash, g_direct_equal); - + name_to_typeinfo = g_hash_table_new (g_str_hash, g_str_equal); + obj_info = g_new (CamelTypeInfo, 1); obj_info->self = camel_object_type; obj_info->parent = CAMEL_INVALID_TYPE; @@ -209,7 +210,8 @@ camel_type_init (void) GINT_TO_POINTER (CAMEL_INVALID_TYPE), NULL); g_hash_table_insert (ctype_to_typeinfo, GINT_TO_POINTER (camel_object_type), obj_info); - + g_hash_table_insert (name_to_typeinfo, obj_info->name, obj_info); + /* Sigh. Ugly */ make_global_classfuncs (obj_info); @@ -243,7 +245,14 @@ camel_type_register (CamelType parent, const gchar * name, camel_type_init (); G_LOCK (type_system); } - + + obj_info = g_hash_table_lookup (name_to_typeinfo, name); + if (obj_info != NULL) { + /* looks like we've already registered this type... */ + camel_type_lock_down (); + return obj_info->self; + } + parent_info = g_hash_table_lookup (ctype_to_typeinfo, GINT_TO_POINTER (parent)); @@ -298,6 +307,7 @@ camel_type_register (CamelType parent, const gchar * name, g_hash_table_insert (ctype_to_typeinfo, GINT_TO_POINTER (obj_info->self), obj_info); + g_hash_table_insert (name_to_typeinfo, obj_info->name, obj_info); /* Sigh. Ugly. */ make_global_classfuncs (obj_info); -- cgit v1.2.3