+ if (!list->array || list->first_elem == list->next_elem) {
+ LeaveCriticalSection (cs);
+ return NULL;
+ }
+ ar = mono_array_get (list->array, MonoObject*, list->first_elem);
+ list->first_elem++;
+ count = list->next_elem - list->first_elem;
+ /* reduce the size of the array if it's mostly empty */
+ if (mono_array_length (list->array) > 16 && count < (mono_array_length (list->array) / 3)) {
+ MonoArray *newa = mono_array_new (mono_get_root_domain (), mono_defaults.object_class, mono_array_length (list->array) / 2);
+ mono_array_memcpy_refs (newa, 0, list->array, list->first_elem, count);
+ list->array = newa;
+ list->first_elem = 0;
+ list->next_elem = count;