File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -2760,7 +2760,7 @@ runtime·markscan(void *v)
2760
2760
void
2761
2761
runtime·markfreed (void * v )
2762
2762
{
2763
- uintptr * b , off , shift ;
2763
+ uintptr * b , off , shift , xbits ;
2764
2764
2765
2765
if (0 )
2766
2766
runtime·printf ("markfreed %p\n" , v );
@@ -2771,7 +2771,18 @@ runtime·markfreed(void *v)
2771
2771
off = (uintptr * )v - (uintptr * )runtime·mheap .arena_start ; // word offset
2772
2772
b = (uintptr * )runtime·mheap .arena_start - off /wordsPerBitmapWord - 1 ;
2773
2773
shift = off % wordsPerBitmapWord ;
2774
- * b = (* b & ~(bitMask <<shift )) | (bitAllocated <<shift );
2774
+ if (!g -> m -> gcing || work .nproc == 1 ) {
2775
+ // During normal operation (not GC), the span bitmap is not updated concurrently,
2776
+ // because either the span is cached or accesses are protected with MCentral lock.
2777
+ * b = (* b & ~(bitMask <<shift )) | (bitAllocated <<shift );
2778
+ } else {
2779
+ // During GC other threads concurrently mark heap.
2780
+ for (;;) {
2781
+ xbits = * b ;
2782
+ if (runtime·casp ((void * * )b , (void * )xbits , (void * )((xbits & ~(bitMask <<shift )) | (bitAllocated <<shift ))))
2783
+ break ;
2784
+ }
2785
+ }
2775
2786
}
2776
2787
2777
2788
// check that the block at v of size n is marked freed.
You can’t perform that action at this time.
0 commit comments