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:
Marco Trevisan (Treviño) 2025-02-19 05:09:34 +01:00
parent 6052374c78
commit 5d117b021a

View File

@ -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;
}