Commit 20ad116a authored by Tomas Bzatek's avatar Tomas Bzatek Committed by Colin Walters

Use GOnce for interface type registration

Static local variable may not be enough since it doesn't provide locking.

Related to these udisksd warnings:
  GLib-GObject-WARNING **: cannot register existing type `PolkitSubject'

Thanks to Hans de Goede for spotting this!

https://bugs.freedesktop.org/show_bug.cgi?id=65130
parent 52e14588
...@@ -49,9 +49,9 @@ base_init (gpointer g_iface) ...@@ -49,9 +49,9 @@ base_init (gpointer g_iface)
GType GType
polkit_identity_get_type (void) polkit_identity_get_type (void)
{ {
static GType iface_type = 0; static volatile gsize g_define_type_id__volatile = 0;
if (iface_type == 0) if (g_once_init_enter (&g_define_type_id__volatile))
{ {
static const GTypeInfo info = static const GTypeInfo info =
{ {
...@@ -67,12 +67,14 @@ polkit_identity_get_type (void) ...@@ -67,12 +67,14 @@ polkit_identity_get_type (void)
NULL /* value_table */ NULL /* value_table */
}; };
iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitIdentity", &info, 0); GType iface_type =
g_type_register_static (G_TYPE_INTERFACE, "PolkitIdentity", &info, 0);
g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT); g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT);
g_once_init_leave (&g_define_type_id__volatile, iface_type);
} }
return iface_type; return g_define_type_id__volatile;
} }
/** /**
......
...@@ -50,9 +50,9 @@ base_init (gpointer g_iface) ...@@ -50,9 +50,9 @@ base_init (gpointer g_iface)
GType GType
polkit_subject_get_type (void) polkit_subject_get_type (void)
{ {
static GType iface_type = 0; static volatile gsize g_define_type_id__volatile = 0;
if (iface_type == 0) if (g_once_init_enter (&g_define_type_id__volatile))
{ {
static const GTypeInfo info = static const GTypeInfo info =
{ {
...@@ -68,12 +68,14 @@ polkit_subject_get_type (void) ...@@ -68,12 +68,14 @@ polkit_subject_get_type (void)
NULL /* value_table */ NULL /* value_table */
}; };
iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitSubject", &info, 0); GType iface_type =
g_type_register_static (G_TYPE_INTERFACE, "PolkitSubject", &info, 0);
g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT); g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT);
g_once_init_leave (&g_define_type_id__volatile, iface_type);
} }
return iface_type; return g_define_type_id__volatile;
} }
/** /**
......
...@@ -74,9 +74,9 @@ base_init (gpointer g_iface) ...@@ -74,9 +74,9 @@ base_init (gpointer g_iface)
GType GType
polkit_backend_action_lookup_get_type (void) polkit_backend_action_lookup_get_type (void)
{ {
static GType iface_type = 0; static volatile gsize g_define_type_id__volatile = 0;
if (iface_type == 0) if (g_once_init_enter (&g_define_type_id__volatile))
{ {
static const GTypeInfo info = static const GTypeInfo info =
{ {
...@@ -92,12 +92,14 @@ polkit_backend_action_lookup_get_type (void) ...@@ -92,12 +92,14 @@ polkit_backend_action_lookup_get_type (void)
NULL /* value_table */ NULL /* value_table */
}; };
iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitBackendActionLookup", &info, 0); GType iface_type =
g_type_register_static (G_TYPE_INTERFACE, "PolkitBackendActionLookup", &info, 0);
g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT); g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT);
g_once_init_leave (&g_define_type_id__volatile, iface_type);
} }
return iface_type; return g_define_type_id__volatile;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment