mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 23:46:17 +01:00
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:
commit
0196a36022
@ -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));
|
||||
|
@ -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 --- */
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user