mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 09:46:17 +01:00
gobject: Use atomic compare and exchange full to force floating
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:
parent
e54f27322d
commit
f792b2ce64
@ -3436,16 +3436,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