diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2017-12-01 11:48:08 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2017-12-01 11:48:08 +0300 |
commit | 31cc9697e40ad05bf92b9570211ad4dd902fc0cc (patch) | |
tree | 0f0cb48337fe417f45e78903ca09d19641e8bd88 /mallocx.c | |
parent | 1dc2066460912e132e5aaf48eac30f6261ed23d9 (diff) | |
download | bdwgc-31cc9697e40ad05bf92b9570211ad4dd902fc0cc.tar.gz |
Workaround TSan warning about data race in generic_malloc_many
It is acceptable to update GC_bytes_found counter without
synchronization (so, it is OK to have inaccurate value in
GC_bytes_found in favor of performance).
* mallocx.c [PARALLEL_MARK && THREAD_SANITIZER]
(GC_generic_malloc_many): Acquire the allocation lock to update
GC_bytes_found (after successful GC_reclaim_generic).
* mallocx.c [PARALLEL_MARK && !THREAD_SANITIZER]
(GC_generic_malloc_many): Move GC_bytes_found update into the block
executed with the mark lock held.
Diffstat (limited to 'mallocx.c')
-rw-r--r-- | mallocx.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -357,11 +357,6 @@ GC_API void GC_CALL GC_generic_malloc_many(size_t lb, int k, void **result) op = GC_reclaim_generic(hbp, hhdr, lb, ok -> ok_init, 0, &my_bytes_allocd); if (op != 0) { - /* We also reclaimed memory, so we need to adjust */ - /* that count. */ - /* This should be atomic, so the results may be */ - /* inaccurate. */ - GC_bytes_found += my_bytes_allocd; # ifdef PARALLEL_MARK if (GC_parallel) { *result = op; @@ -370,11 +365,23 @@ GC_API void GC_CALL GC_generic_malloc_many(size_t lb, int k, void **result) GC_acquire_mark_lock(); -- GC_fl_builder_count; if (GC_fl_builder_count == 0) GC_notify_all_builder(); - GC_release_mark_lock(); +# ifdef THREAD_SANITIZER + GC_release_mark_lock(); + LOCK(); + GC_bytes_found += my_bytes_allocd; + UNLOCK(); +# else + GC_bytes_found += my_bytes_allocd; + /* The result may be inaccurate. */ + GC_release_mark_lock(); +# endif (void) GC_clear_stack(0); return; } # endif + /* We also reclaimed memory, so we need to adjust */ + /* that count. */ + GC_bytes_found += my_bytes_allocd; GC_bytes_allocd += my_bytes_allocd; goto out; } |