[glib/gobject-performance-2] Fix possible race in lookup_iface_entry_I
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib/gobject-performance-2] Fix possible race in lookup_iface_entry_I
- Date: Fri, 27 Nov 2009 16:07:29 +0000 (UTC)
commit 9233b07e27be3ffe89695aaa6fc083a36daa037a
Author: Alexander Larsson <alexl redhat com>
Date: Fri Nov 27 16:53:44 2009 +0100
Fix possible race in lookup_iface_entry_I
entries can change at any time, since its from an atomicarray. So,
when we've read entries->offset_index and checked it for the
limits we need to make sure we use the read value and don't
re-read the memory again.
Also, to ensure the compiler doesn't do this anyway, make entries
volatile.
gobject/gtype.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gobject/gtype.c b/gobject/gtype.c
index cdce8eb..b216ad8 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -531,10 +531,11 @@ type_node_new_W (TypeNode *pnode,
}
static inline IFaceEntry*
-lookup_iface_entry_I (IFaceEntries *entries,
+lookup_iface_entry_I (volatile IFaceEntries *entries,
TypeNode *iface_node)
{
guint8 *offsets;
+ guint offset_index;
IFaceEntry *check;
int index;
IFaceEntry *entry;
@@ -547,10 +548,11 @@ lookup_iface_entry_I (IFaceEntries *entries,
entry = NULL;
offsets = transaction_data;
+ offset_index = entries->offset_index;
if (offsets != NULL &&
- entries->offset_index < G_ATOMIC_ARRAY_DATA_SIZE(offsets))
+ offset_index < G_ATOMIC_ARRAY_DATA_SIZE(offsets))
{
- index = offsets[entries->offset_index];
+ index = offsets[offset_index];
if (index > 0)
{
/* zero means unset, subtract one to get real index */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]