diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-11-01 00:28:21 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-11-14 22:30:44 +0300 |
commit | cfd7456be495732cca7e1fd1f9c58cd2cbcad4fd (patch) | |
tree | 1cc344d435d6de1069ee6b02ad798c0af4de65bb | |
parent | e3b3bbb465833ff88d3d43c96b80e68f2982b8d3 (diff) | |
download | bdwgc-cfd7456be495732cca7e1fd1f9c58cd2cbcad4fd.tar.gz |
Fix data race in GC_heapsize_at_forced_unmap variable
(a cherry-pick of commit 856760844 from 'release-8_2')
Issue #488 (bdwgc).
Write to GC_heapsize_at_forced_unmap should be only performed when
holding the allocation lock.
* alloc.c (GC_heapsize_at_forced_unmap): Move the definition upper to
be before GC_try_to_collect_general(); add comment.
* alloc.c (GC_try_to_collect_general): Set GC_heapsize_at_forced_unmap
value (after LOCK) if force_unmap; move comment from
GC_heapsize_at_forced_unmap().
* alloc.c (GC_try_to_collect_general): Remove GC_ATTR_UNUSED for
force_unmap.
* alloc.c (GC_gcollect_and_unmap): Do not set
GC_heapsize_at_forced_unmap.
-rw-r--r-- | alloc.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -1134,9 +1134,12 @@ STATIC void GC_finish_collection(void) # endif } +STATIC word GC_heapsize_at_forced_unmap = 0; + /* accessed with the allocation lock held */ + /* If stop_func == 0 then GC_default_stop_func is used instead. */ STATIC GC_bool GC_try_to_collect_general(GC_stop_func stop_func, - GC_bool force_unmap GC_ATTR_UNUSED) + GC_bool force_unmap) { GC_bool result; IF_USE_MUNMAP(int old_unmap_threshold;) @@ -1147,6 +1150,11 @@ STATIC GC_bool GC_try_to_collect_general(GC_stop_func stop_func, if (GC_debugging_started) GC_print_all_smashed(); GC_INVOKE_FINALIZERS(); LOCK(); + if (force_unmap) { + /* Record current heap size to make heap growth more conservative */ + /* afterwards (as if the heap is growing from zero size again). */ + GC_heapsize_at_forced_unmap = GC_heapsize; + } DISABLE_CANCEL(cancel_state); # ifdef USE_MUNMAP old_unmap_threshold = GC_unmap_threshold; @@ -1185,13 +1193,8 @@ GC_API void GC_CALL GC_gcollect(void) if (GC_have_errors) GC_print_all_errors(); } -STATIC word GC_heapsize_at_forced_unmap = 0; - GC_API void GC_CALL GC_gcollect_and_unmap(void) { - /* Record current heap size to make heap growth more conservative */ - /* afterwards (as if the heap is growing from zero size again). */ - GC_heapsize_at_forced_unmap = GC_heapsize; /* Collect and force memory unmapping to OS. */ (void)GC_try_to_collect_general(GC_never_stop_func, TRUE); } |