Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 1 | From 47da8ec5d9a284e07f77c7d59fc8eacf3ebf188a Mon Sep 17 00:00:00 2001 |
| 2 | From: Philip Withnall <pwithnall@endlessos.org> |
| 3 | Date: Mon, 16 Nov 2020 16:57:22 +0000 |
| 4 | Subject: [PATCH 27/29] gtype: Add some missing atomic accesses to init_state |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | Half of the references to `init_state` in `gtype.c` already correctly |
| 10 | accessed it atomically, but a couple didn’t. Drop the `volatile` |
| 11 | qualifier from its declaration, as that’s not necessary for atomic |
| 12 | access. |
| 13 | |
| 14 | Note that this is the `init_state` in `TypeData`, *not* the `init_state` |
| 15 | in `IFaceEntry`. |
| 16 | |
| 17 | Signed-off-by: Philip Withnall <pwithnall@endlessos.org> |
| 18 | |
| 19 | Helps: #600 |
| 20 | Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719] |
| 21 | --- |
| 22 | gobject/gtype.c | 10 +++++----- |
| 23 | 1 file changed, 5 insertions(+), 5 deletions(-) |
| 24 | |
| 25 | diff --git a/gobject/gtype.c b/gobject/gtype.c |
| 26 | index ae1af8a05..909faf138 100644 |
| 27 | --- a/gobject/gtype.c |
| 28 | +++ b/gobject/gtype.c |
| 29 | @@ -322,7 +322,7 @@ struct _ClassData |
| 30 | CommonData common; |
| 31 | guint16 class_size; |
| 32 | guint16 class_private_size; |
| 33 | - int volatile init_state; /* atomic - g_type_class_ref reads it unlocked */ |
| 34 | + int init_state; /* (atomic) - g_type_class_ref reads it unlocked */ |
| 35 | GBaseInitFunc class_init_base; |
| 36 | GBaseFinalizeFunc class_finalize_base; |
| 37 | GClassInitFunc class_init; |
| 38 | @@ -336,7 +336,7 @@ struct _InstanceData |
| 39 | CommonData common; |
| 40 | guint16 class_size; |
| 41 | guint16 class_private_size; |
| 42 | - int volatile init_state; /* atomic - g_type_class_ref reads it unlocked */ |
| 43 | + int init_state; /* (atomic) - g_type_class_ref reads it unlocked */ |
| 44 | GBaseInitFunc class_init_base; |
| 45 | GBaseFinalizeFunc class_finalize_base; |
| 46 | GClassInitFunc class_init; |
| 47 | @@ -1415,7 +1415,7 @@ type_node_add_iface_entry_W (TypeNode *node, |
| 48 | |
| 49 | if (parent_entry) |
| 50 | { |
| 51 | - if (node->data && node->data->class.init_state >= BASE_IFACE_INIT) |
| 52 | + if (node->data && g_atomic_int_get (&node->data->class.init_state) >= BASE_IFACE_INIT) |
| 53 | { |
| 54 | entries->entry[i].init_state = INITIALIZED; |
| 55 | entries->entry[i].vtable = parent_entry->vtable; |
| 56 | @@ -1481,7 +1481,7 @@ type_add_interface_Wm (TypeNode *node, |
| 57 | */ |
| 58 | if (node->data) |
| 59 | { |
| 60 | - InitState class_state = node->data->class.init_state; |
| 61 | + InitState class_state = g_atomic_int_get (&node->data->class.init_state); |
| 62 | |
| 63 | if (class_state >= BASE_IFACE_INIT) |
| 64 | type_iface_vtable_base_init_Wm (iface, node); |
| 65 | @@ -2175,7 +2175,7 @@ type_class_init_Wm (TypeNode *node, |
| 66 | g_assert (node->is_classed && node->data && |
| 67 | node->data->class.class_size && |
| 68 | !node->data->class.class && |
| 69 | - node->data->class.init_state == UNINITIALIZED); |
| 70 | + g_atomic_int_get (&node->data->class.init_state) == UNINITIALIZED); |
| 71 | if (node->data->class.class_private_size) |
| 72 | class = g_malloc0 (ALIGN_STRUCT (node->data->class.class_size) + node->data->class.class_private_size); |
| 73 | else |
| 74 | -- |
| 75 | 2.30.1 |
| 76 | |