mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
gdataset: update pointers at end of g_datalist_id_replace_data()
- when setting datalist to NULL, do it at the end with g_datalist_unlock_and_set() to avoid the additional atomic operations. - when freeing the old "d", do that after releasing the bit lock.
This commit is contained in:
parent
a426410919
commit
435aa01158
@ -963,6 +963,8 @@ g_datalist_id_replace_data (GData **datalist,
|
||||
GData *d;
|
||||
GData *new_d = NULL;
|
||||
GDataElt *data, *data_end;
|
||||
gboolean free_d = FALSE;
|
||||
gboolean set_new_d = FALSE;
|
||||
|
||||
g_return_val_if_fail (datalist != NULL, FALSE);
|
||||
g_return_val_if_fail (key_id != 0, FALSE);
|
||||
@ -1002,8 +1004,8 @@ g_datalist_id_replace_data (GData **datalist,
|
||||
*/
|
||||
if (d->len == 0)
|
||||
{
|
||||
G_DATALIST_SET_POINTER (datalist, NULL);
|
||||
g_free (d);
|
||||
set_new_d = TRUE;
|
||||
free_d = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1031,7 +1033,10 @@ g_datalist_id_replace_data (GData **datalist,
|
||||
d = g_realloc (d, sizeof (GData) + (d->alloc - 1) * sizeof (GDataElt));
|
||||
}
|
||||
if (old_d != d)
|
||||
new_d = d;
|
||||
{
|
||||
new_d = d;
|
||||
set_new_d = TRUE;
|
||||
}
|
||||
|
||||
d->data[d->len].key = key_id;
|
||||
d->data[d->len].data = newval;
|
||||
@ -1039,11 +1044,14 @@ g_datalist_id_replace_data (GData **datalist,
|
||||
d->len++;
|
||||
}
|
||||
|
||||
if (new_d)
|
||||
if (set_new_d)
|
||||
g_datalist_unlock_and_set (datalist, new_d);
|
||||
else
|
||||
g_datalist_unlock (datalist);
|
||||
|
||||
if (free_d)
|
||||
g_free (d);
|
||||
|
||||
return val == oldval;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user