diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-12-14 04:38:11 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-12-14 04:38:11 +0800 |
commit | 66587d89a30adfd7251dfd586e6213f9e9c536a0 (patch) | |
tree | f67f41fe3a63c1e1ceda889068eb7bc4c506381f /camel/camel-object.c | |
parent | e2f8314f13c805cc9991f604f8609723ed1ec372 (diff) | |
download | gsoc2013-evolution-66587d89a30adfd7251dfd586e6213f9e9c536a0.tar.gz gsoc2013-evolution-66587d89a30adfd7251dfd586e6213f9e9c536a0.tar.zst gsoc2013-evolution-66587d89a30adfd7251dfd586e6213f9e9c536a0.zip |
Keep a name-to-type hash so that we can make sure that the type has not
2001-12-11 Jeffrey Stedfast <fejj@ximian.com>
* 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
Diffstat (limited to 'camel/camel-object.c')
-rw-r--r-- | camel/camel-object.c | 20 |
1 files changed, 15 insertions, 5 deletions
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); |