mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
Make g_type_class_peek[_static]() not take any locks
By replacing a check for node->data with a check for NODE_REFCOUNT(node) these functions don't require a read lock anymore.
This commit is contained in:
parent
83ee0d947d
commit
5cac5c828b
@ -2950,14 +2950,12 @@ g_type_class_peek (GType type)
|
|||||||
gpointer class;
|
gpointer class;
|
||||||
|
|
||||||
node = lookup_type_node_I (type);
|
node = lookup_type_node_I (type);
|
||||||
G_READ_LOCK (&type_rw_lock);
|
if (node && node->is_classed && NODE_REFCOUNT (node) > 0 &&
|
||||||
if (node && node->is_classed && node->data &&
|
|
||||||
g_atomic_int_get (&node->data->class.init_state) == INITIALIZED)
|
g_atomic_int_get (&node->data->class.init_state) == INITIALIZED)
|
||||||
/* ref_count _may_ be 0 */
|
/* ref_count _may_ be 0 */
|
||||||
class = node->data->class.class;
|
class = node->data->class.class;
|
||||||
else
|
else
|
||||||
class = NULL;
|
class = NULL;
|
||||||
G_READ_UNLOCK (&type_rw_lock);
|
|
||||||
|
|
||||||
return class;
|
return class;
|
||||||
}
|
}
|
||||||
@ -2980,15 +2978,13 @@ g_type_class_peek_static (GType type)
|
|||||||
gpointer class;
|
gpointer class;
|
||||||
|
|
||||||
node = lookup_type_node_I (type);
|
node = lookup_type_node_I (type);
|
||||||
G_READ_LOCK (&type_rw_lock);
|
if (node && node->is_classed && NODE_REFCOUNT (node) &&
|
||||||
if (node && node->is_classed && node->data &&
|
|
||||||
/* peek only static types: */ node->plugin == NULL &&
|
/* peek only static types: */ node->plugin == NULL &&
|
||||||
g_atomic_int_get (&node->data->class.init_state) == INITIALIZED)
|
g_atomic_int_get (&node->data->class.init_state) == INITIALIZED)
|
||||||
/* ref_count _may_ be 0 */
|
/* ref_count _may_ be 0 */
|
||||||
class = node->data->class.class;
|
class = node->data->class.class;
|
||||||
else
|
else
|
||||||
class = NULL;
|
class = NULL;
|
||||||
G_READ_UNLOCK (&type_rw_lock);
|
|
||||||
|
|
||||||
return class;
|
return class;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user