[sgen] Set the block state to CHECKING with the allocated blocks lock held.
authorMark Probst <mark.probst@gmail.com>
Mon, 26 Jan 2015 18:18:32 +0000 (13:18 -0500)
committerMark Probst <mark.probst@gmail.com>
Thu, 2 Apr 2015 23:41:24 +0000 (16:41 -0700)
mono/metadata/sgen-marksweep.c

index 06216eb8d3b2309e47f04efa31a681231cba8d67..f18ad82fe1697c749a3a8207e78922cf47d287d6 100644 (file)
@@ -1317,6 +1317,11 @@ sweep_start (void)
 
 static void sweep_finish (void);
 
+/*
+ * LOCKING: The allocated blocks lock must be held when entering this function.  `block`
+ * must have been loaded from the array with the lock held.  This function will unlock the
+ * lock.
+ */
 static void
 check_block_for_sweeping (MSBlockInfo *block, int block_index)
 {
@@ -1329,6 +1334,7 @@ check_block_for_sweeping (MSBlockInfo *block, int block_index)
        block->swept = 0;
        SGEN_ASSERT (0, block->state == BLOCK_STATE_MARKING, "When we sweep all blocks must start out marking.");
        set_block_state (block, BLOCK_STATE_CHECKING, BLOCK_STATE_MARKING);
+       UNLOCK_ALLOCATED_BLOCKS;
 
        assert_block_state_is_consistent (block);
 
@@ -1428,12 +1434,13 @@ sweep_loop_thread_func (void *dummy)
 
                LOCK_ALLOCATED_BLOCKS;
                block = BLOCK_UNTAG_HAS_REFERENCES (allocated_blocks.data [block_index]);
-               UNLOCK_ALLOCATED_BLOCKS;
 
                assert_block_state_is_consistent (block);
 
-               if (block->state == BLOCK_STATE_SWEPT)
+               if (block->state == BLOCK_STATE_SWEPT) {
+                       UNLOCK_ALLOCATED_BLOCKS;
                        continue;
+               }
 
                check_block_for_sweeping (block, block_index);
        }