X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fsgen%2Fsgen-array-list.c;h=2fd54d986d0d6ded4b26dc3efb5203198bd4d3ec;hb=7d68dc8e71623ba76b16c5c5aa597a2fc7783f16;hp=09ac01dfd5e8ee88f365d618b551d1b9a84c5be4;hpb=4c960e1dd530396fdd9400c87729a6ce3101e5c1;p=mono.git diff --git a/mono/sgen/sgen-array-list.c b/mono/sgen/sgen-array-list.c index 09ac01dfd5e..2fd54d986d0 100644 --- a/mono/sgen/sgen-array-list.c +++ b/mono/sgen/sgen-array-list.c @@ -1,5 +1,6 @@ -/* - * sgen-array-list.c: A pointer array list that doesn't require reallocs +/** + * \file + * A pointer array list that doesn't require reallocs * * Copyright (C) 2016 Xamarin Inc * @@ -177,37 +178,56 @@ retry: } /* - * Removes all NULL pointers from the array. Not thread safe + * Does a linear search through the pointer array to find `ptr`. Returns the index if + * found, otherwise (guint32)-1. */ -void -sgen_array_list_remove_nulls (SgenArrayList *array) +guint32 +sgen_array_list_find (SgenArrayList *array, gpointer ptr) { - guint32 start = 0; volatile gpointer *slot; SGEN_ARRAY_LIST_FOREACH_SLOT (array, slot) { - if (*slot) - *sgen_array_list_get_slot (array, start++) = *slot; + if (*slot == ptr) + return __index; } SGEN_ARRAY_LIST_END_FOREACH_SLOT; + return (guint32)-1; +} - mono_memory_write_barrier (); - array->next_slot = start; +gboolean +sgen_array_list_default_cas_setter (volatile gpointer *slot, gpointer ptr, int data) +{ + if (InterlockedCompareExchangePointer (slot, ptr, NULL) == NULL) + return TRUE; + return FALSE; } -/* - * Does a linear search through the pointer array to find `ptr`. Returns the index if - * found, otherwise (guint32)-1. - */ -guint32 -sgen_array_list_find (SgenArrayList *array, gpointer ptr) +gboolean +sgen_array_list_default_is_slot_set (volatile gpointer *slot) +{ + return *slot != NULL; +} + +/* Removes all NULL pointers from the array. Not thread safe */ +void +sgen_array_list_remove_nulls (SgenArrayList *array) { + guint32 start = 0; volatile gpointer *slot; + gboolean skipped = FALSE; SGEN_ARRAY_LIST_FOREACH_SLOT (array, slot) { - if (*slot == ptr) - return __index; + if (*slot) { + *sgen_array_list_get_slot (array, start++) = *slot; + if (skipped) + *slot = NULL; + } else { + skipped = TRUE; + } } SGEN_ARRAY_LIST_END_FOREACH_SLOT; - return (guint32)-1; + + mono_memory_write_barrier (); + array->next_slot = start; + array->slot_hint = start; } #endif