gdataset: Use atomic compare and exchange full to set pointers

In case first exchange failed we can avoid repeating the pointer get
operation given that exchange full can provide us the old value.
This commit is contained in:
Marco Trevisan (Treviño) 2023-05-09 14:06:21 +02:00
parent 08aee6b5f4
commit e54f27322d

View File

@ -145,11 +145,12 @@
((GData*) ((gsize) g_atomic_pointer_get (datalist) & ~(gsize) G_DATALIST_FLAGS_MASK_INTERNAL))
#define G_DATALIST_SET_POINTER(datalist, pointer) G_STMT_START { \
gpointer _oldv, _newv; \
gpointer _oldv = g_atomic_pointer_get (datalist); \
gpointer _newv; \
do { \
_oldv = g_atomic_pointer_get (datalist); \
_newv = (gpointer) (((gsize) _oldv & G_DATALIST_FLAGS_MASK_INTERNAL) | (gsize) pointer); \
} while (!g_atomic_pointer_compare_and_exchange ((void**) datalist, _oldv, _newv)); \
} while (!g_atomic_pointer_compare_and_exchange_full ((void**) datalist, _oldv, \
_newv, &_oldv)); \
} G_STMT_END
/* --- structures --- */