glib/gobject
Sam James 190d6d3a91 gclosure: fix ATOMIC_CHANGE_FIELD to read vint atomically
Depending on luck, g_closure_ref may access closure->vint and observe
different values between reads. This manifests as a test failure in
signals-refcount{2,4}, properties-refcount1, and closure-refcount depending
on timing and re-runs.

Jakub Jelinek analysed this on GCC bug PR119607 after I'd reported it
over there as a possible GCC regression.

The critical part being g_closure_ref -> ATOMIC_INC_ASSIGN -> ATOMIC_CHANGE_FIELD
where closure->vint gets re-read repeatedly, both outside and inside the retry
loop. To fix that:

1. Atomically fetch it the first time;
2. Use the cached read, not a fresh read, of vint in the loop;
3. Use g_atomic_int_compare_and_exchange_full in the loop so we get a freshly
cached vint if it changed in another thread.

Bug: https://gcc.gnu.org/PR119607
Fixes: 834ddd19 ('turned all modifications to the first 32 integer bits in a closure into')
Co-authored-by: Jakub Jelinek <jakub@redhat.com>
2025-04-03 23:40:30 +01:00
..
2023-10-16 23:34:04 +01:00
2023-12-31 09:09:48 +00:00
2022-10-13 20:53:56 -04:00
2023-10-16 23:35:05 +01:00
2023-12-31 09:09:48 +00:00
2022-10-13 20:53:56 -04:00
2023-10-16 23:34:24 +01:00
2022-10-13 20:53:56 -04:00
2022-10-13 20:53:56 -04:00
2025-02-03 14:38:24 +00:00
2025-02-10 10:26:42 +01:00
2023-10-23 11:26:53 +01:00
2022-10-13 20:53:56 -04:00