mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
gmain: Avoid unneeded atomic read on GSource ref
In g_source_ref() we can just ensure that the value we've referenced was valid, instead of checking it before, since if get to such state the GSource is broken anyways, but at least we can avoid doing an unneeded atomic read. Reason why we don't bother resetting the reference in case of failure.
This commit is contained in:
parent
6052374c78
commit
5d117b021a
@ -2191,12 +2191,13 @@ g_source_set_name_by_id (guint tag,
|
||||
GSource *
|
||||
g_source_ref (GSource *source)
|
||||
{
|
||||
int old_ref G_GNUC_UNUSED;
|
||||
g_return_val_if_fail (source != NULL, NULL);
|
||||
|
||||
old_ref = g_atomic_int_add (&source->ref_count, 1);
|
||||
/* We allow ref_count == 0 here to allow the dispose function to resurrect
|
||||
* the GSource if needed */
|
||||
g_return_val_if_fail (g_atomic_int_get (&source->ref_count) >= 0, NULL);
|
||||
|
||||
g_atomic_int_inc (&source->ref_count);
|
||||
g_return_val_if_fail (old_ref >= 0, NULL);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user