Use a critical region in mono_gc_alloc_array.
authoralexrp <xtzgzorex@gmail.com>
Mon, 9 Jul 2012 23:14:53 +0000 (01:14 +0200)
committeralexrp <xtzgzorex@gmail.com>
Mon, 9 Jul 2012 23:36:31 +0000 (01:36 +0200)
mono/metadata/sgen-alloc.c

index 7896c31292aed6725c0da30f937933d8a7988596..86095e5d0427fdb2da4b9b22d8f8835c86c747c6 100644 (file)
@@ -474,6 +474,22 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
        MonoArray *arr;
        MonoArrayBounds *bounds;
 
+#ifndef DISABLE_CRITICAL_REGION
+       TLAB_ACCESS_INIT;
+       ENTER_CRITICAL_REGION;
+       arr = mono_gc_try_alloc_obj_nolock (vtable, size);
+       if (arr) {
+               /*This doesn't require fencing since EXIT_CRITICAL_REGION already does it for us*/
+               arr->max_length = max_length;
+
+               bounds = (MonoArrayBounds*)((char*)arr + size - bounds_size);
+               arr->bounds = bounds;
+               EXIT_CRITICAL_REGION;
+               return arr;
+       }
+       EXIT_CRITICAL_REGION;
+#endif
+
        LOCK_GC;
 
        arr = mono_gc_alloc_obj_nolock (vtable, size);