diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2022-06-21 05:01:55 +0200 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2022-06-23 20:01:12 +0200 |
commit | 2c322f2a650bc60dcbb254746352af420d515d2c (patch) | |
tree | 8b6e3146cd27fc394ec13285cdd5a6cedf6f6973 | |
parent | bfd77693cedc37713b6f1799a694fd44af9ccfe2 (diff) | |
download | glib-2c322f2a650bc60dcbb254746352af420d515d2c.tar.gz |
gmain: Do atomic addition before checking the old value on ref
So we avoid working on a value that is not been updated yet.
-rw-r--r-- | glib/gmain.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/glib/gmain.c b/glib/gmain.c index a0ade8acb..6571fa239 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -551,10 +551,12 @@ GSourceFuncs g_idle_funcs = GMainContext * g_main_context_ref (GMainContext *context) { + int old_ref_count; + g_return_val_if_fail (context != NULL, NULL); - g_return_val_if_fail (g_atomic_int_get (&context->ref_count) > 0, NULL); - g_atomic_int_inc (&context->ref_count); + old_ref_count = g_atomic_int_add (&context->ref_count, 1); + g_return_val_if_fail (old_ref_count > 0, NULL); return context; } |