mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-14 08:16:24 +01:00
gmain: Do atomic addition before checking the old value on ref
So we avoid working on a value that is not been updated yet.
This commit is contained in:
parent
bfd77693ce
commit
2c322f2a65
@ -551,10 +551,12 @@ GSourceFuncs g_idle_funcs =
|
||||
GMainContext *
|
||||
g_main_context_ref (GMainContext *context)
|
||||
{
|
||||
g_return_val_if_fail (context != NULL, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&context->ref_count) > 0, NULL);
|
||||
int old_ref_count;
|
||||
|
||||
g_atomic_int_inc (&context->ref_count);
|
||||
g_return_val_if_fail (context != NULL, NULL);
|
||||
|
||||
old_ref_count = g_atomic_int_add (&context->ref_count, 1);
|
||||
g_return_val_if_fail (old_ref_count > 0, NULL);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user