Merge branch 'more-atomic-exchange-full' into 'main'

gdataset, gobject: Use atomic compare and exchange full to set pointers

See merge request GNOME/glib!3426
This commit is contained in:
Philip Withnall 2023-05-30 11:59:40 +00:00
commit 0196a36022
3 changed files with 22 additions and 18 deletions

View File

@ -1364,11 +1364,10 @@ g_resources_get_info (const gchar *path,
static void
register_lazy_static_resources_unlocked (void)
{
GStaticResource *list;
GStaticResource *list = g_atomic_pointer_get (&lazy_register_resources);
do
list = lazy_register_resources;
while (!g_atomic_pointer_compare_and_exchange (&lazy_register_resources, list, NULL));
while (!g_atomic_pointer_compare_and_exchange_full (&lazy_register_resources, list, NULL, &list))
;
while (list != NULL)
{
@ -1416,7 +1415,7 @@ g_static_resource_init (GStaticResource *static_resource)
do
{
next = lazy_register_resources;
next = g_atomic_pointer_get (&lazy_register_resources);
static_resource->next = next;
}
while (!g_atomic_pointer_compare_and_exchange (&lazy_register_resources, next, static_resource));

View File

@ -144,12 +144,13 @@
#define G_DATALIST_GET_POINTER(datalist) \
((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; \
do { \
_oldv = g_atomic_pointer_get (datalist); \
#define G_DATALIST_SET_POINTER(datalist, pointer) G_STMT_START { \
gpointer _oldv = g_atomic_pointer_get (datalist); \
gpointer _newv; \
do { \
_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 --- */

View File

@ -3435,16 +3435,20 @@ object_floating_flag_handler (GObject *object,
{
gpointer oldvalue;
case +1: /* force floating if possible */
do
oldvalue = g_atomic_pointer_get (&object->qdata);
while (!g_atomic_pointer_compare_and_exchange ((void**) &object->qdata, oldvalue,
(gpointer) ((gsize) oldvalue | OBJECT_FLOATING_FLAG)));
oldvalue = g_atomic_pointer_get (&object->qdata);
while (!g_atomic_pointer_compare_and_exchange_full (
(void**) &object->qdata, oldvalue,
(void *) ((gsize) oldvalue | OBJECT_FLOATING_FLAG),
&oldvalue))
;
return (gsize) oldvalue & OBJECT_FLOATING_FLAG;
case -1: /* sink if possible */
do
oldvalue = g_atomic_pointer_get (&object->qdata);
while (!g_atomic_pointer_compare_and_exchange ((void**) &object->qdata, oldvalue,
(gpointer) ((gsize) oldvalue & ~(gsize) OBJECT_FLOATING_FLAG)));
oldvalue = g_atomic_pointer_get (&object->qdata);
while (!g_atomic_pointer_compare_and_exchange_full (
(void**) &object->qdata, oldvalue,
(void *) ((gsize) oldvalue & ~(gsize) OBJECT_FLOATING_FLAG),
&oldvalue))
;
return (gsize) oldvalue & OBJECT_FLOATING_FLAG;
default: /* check floating */
return 0 != ((gsize) g_atomic_pointer_get (&object->qdata) & OBJECT_FLOATING_FLAG);