summaryrefslogtreecommitdiff
path: root/mark.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-05-13 21:29:28 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-05-19 12:15:03 +0300
commite338ee5fa6057d44308baf69dbb56c118317e493 (patch)
treed6a01d23afc64e7cc547c25c1aebfa0fe3d7062f /mark.c
parent28ebb9dccd215f8156a5b95335f0bfa021709fd4 (diff)
downloadbdwgc-e338ee5fa6057d44308baf69dbb56c118317e493.tar.gz
Ensure GC_our_memory is updated while holding GC lock
(refactoring) * alloc.c [USE_PROC_FOR_LIBRARIES] (GC_add_to_our_memory): Add assertion that the GC lock is held. * backgraph.c (new_back_edges): Likewise. * misc.c [GC_READ_ENV_FILE] (GC_envfile_init): Likewise. * mark.c [PARALLEL_MARK] (GC_wait_for_markers_init): Add assertion that the GC lock is not hold on entrance; wrap GC_add_to_our_memory() call into LOCK/UNLOCK. * mark.c [PARALLEL_MARK] (GC_do_parallel_mark): Move assertion about the GC lock to be the first statement. * misc.c [GC_ASSERTIONS && GC_ALWAYS_MULTITHREADED] (GC_init): Move the first call of LOCK() upper to be before GC_envfile_init(). * misc.c [LINT2] (GC_init): Set GC_dont_gc directly (instead of GC_disable() call) if GC_ASSERTIONS and GC_ALWAYS_MULTITHREADED.
Diffstat (limited to 'mark.c')
-rw-r--r--mark.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/mark.c b/mark.c
index 0ee9b971..b005a1d2 100644
--- a/mark.c
+++ b/mark.c
@@ -924,6 +924,7 @@ GC_INNER void GC_wait_for_markers_init(void)
{
signed_word count;
+ GC_ASSERT(I_DONT_HOLD_LOCK());
if (GC_markers_m1 == 0)
return;
@@ -936,12 +937,15 @@ GC_INNER void GC_wait_for_markers_init(void)
{
size_t bytes_to_get =
ROUNDUP_PAGESIZE_IF_MMAP(LOCAL_MARK_STACK_SIZE * sizeof(mse));
+ DCL_LOCK_STATE;
GC_ASSERT(GC_page_size != 0);
GC_main_local_mark_stack = (mse *)GET_MEM(bytes_to_get);
if (NULL == GC_main_local_mark_stack)
ABORT("Insufficient memory for main local_mark_stack");
+ LOCK();
GC_add_to_our_memory((ptr_t)GC_main_local_mark_stack, bytes_to_get);
+ UNLOCK();
}
/* Reuse marker lock and builders count to synchronize */
@@ -1194,8 +1198,8 @@ STATIC void GC_mark_local(mse *local_mark_stack, int id)
/* Currently runs until the mark stack is empty. */
STATIC void GC_do_parallel_mark(void)
{
- GC_acquire_mark_lock();
GC_ASSERT(I_HOLD_LOCK());
+ GC_acquire_mark_lock();
/* This could be a GC_ASSERT, but it seems safer to keep it on */
/* all the time, especially since it's cheap. */