[glib] Add g_type_get_type_registration_serial()
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add g_type_get_type_registration_serial()
- Date: Mon, 10 Dec 2012 11:56:06 +0000 (UTC)
commit e218b96a6bf687842834fbfe133e77495049f251
Author: Alexander Larsson <alexl redhat com>
Date: Fri Dec 7 17:34:52 2012 +0100
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
docs/reference/gobject/gobject-sections.txt | 1 +
gobject/gobject.symbols | 1 +
gobject/gtype.c | 23 +++++++++++++++++++++++
gobject/gtype.h | 3 +++
4 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index e5d2cbe..4b48e3e 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 8297734..279d911 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 5fef634..d02aece 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 80a4ddf..dec1d89 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 --- */
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]