Add g_type_get_type_registration_serial()

This lets you cache type lookup information and then know when
the cache information is out of date. In particular, we want this
in order to be able to cache g_type_from_name() lookups in the Gtk+
theme machinery.

https://bugzilla.gnome.org/show_bug.cgi?id=689847
This commit is contained in:
Alexander Larsson 2012-12-07 17:34:52 +01:00
parent d77948eadf
commit e218b96a6b
4 changed files with 28 additions and 0 deletions

View File

@ -99,6 +99,7 @@ g_type_remove_interface_check
GTypeInterfaceCheckFunc
g_type_value_table_peek
g_type_ensure
g_type_get_type_registration_serial
G_DEFINE_TYPE
G_DEFINE_TYPE_WITH_CODE

View File

@ -350,6 +350,7 @@ g_type_fundamental
g_type_fundamental_next
g_type_get_plugin
g_type_get_qdata
g_type_get_type_registration_serial
g_type_init
g_type_init_with_debug_flags
g_type_instance_get_private

View File

@ -377,6 +377,7 @@ static IFaceCheckFunc *static_iface_check_funcs = NULL;
static GQuark static_quark_type_flags = 0;
static GQuark static_quark_iface_holder = 0;
static GQuark static_quark_dependants_array = 0;
static guint type_registration_serial = 0;
GTypeDebugFlags _g_type_debug_flags = 0;
/* --- type nodes --- */
@ -393,6 +394,25 @@ lookup_type_node_I (register GType utype)
return static_fundamental_type_nodes[utype >> G_TYPE_FUNDAMENTAL_SHIFT];
}
/**
* g_type_get_type_registration_serial:
*
* Returns an opaque serial number that represents the state of the set of registered
* types. Any time a type is registred this serial changes, which means you can
* cache information based on type lookups (such as g_type_from_name) and know if
* the cache is still valid at a later time by comparing the current serial with
* the one at the type lookup.
*
* Since: 2.36
*
* Returns: An unsigned int, representing the state of type registrations.
*/
guint
g_type_get_type_registration_serial (void)
{
return (guint)g_atomic_int_get ((gint *)&type_registration_serial);
}
static TypeNode*
type_node_any_new_W (TypeNode *pnode,
GType ftype,
@ -490,6 +510,9 @@ type_node_any_new_W (TypeNode *pnode,
g_hash_table_insert (static_type_nodes_ht,
(gpointer) g_quark_to_string (node->qname),
(gpointer) type);
g_atomic_int_inc ((gint *)&type_registration_serial);
return node;
}

View File

@ -1263,6 +1263,9 @@ gpointer g_type_class_get_private (GTypeClass *klass,
GLIB_AVAILABLE_IN_2_34
void g_type_ensure (GType type);
GLIB_AVAILABLE_IN_2_36
guint g_type_get_type_registration_serial (void);
/* --- GType boilerplate --- */
/**