diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt index e5d2cbec6..4b48e3edc 100644 --- a/docs/reference/gobject/gobject-sections.txt +++ b/docs/reference/gobject/gobject-sections.txt @@ -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 diff --git a/gobject/gobject.symbols b/gobject/gobject.symbols index 829773452..279d9116b 100644 --- a/gobject/gobject.symbols +++ b/gobject/gobject.symbols @@ -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 diff --git a/gobject/gtype.c b/gobject/gtype.c index 5fef634d7..d02aeceab 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -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; } diff --git a/gobject/gtype.h b/gobject/gtype.h index 80a4ddf24..dec1d8976 100644 --- a/gobject/gtype.h +++ b/gobject/gtype.h @@ -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 --- */ /**