diff options
author | Ray Johnston <ray.johnston@artifex.com> | 2020-09-26 18:36:16 -0700 |
---|---|---|
committer | Ray Johnston <ray.johnston@artifex.com> | 2020-10-31 23:39:45 -0700 |
commit | eec6fd158ee477facfb4bf9edd4e99506c195732 (patch) | |
tree | 8e57dd3ef349c0ba43d5032374195e258ab555a5 /base/gsmalloc.c | |
parent | 13ed12281b6b60804172a6844081a9ea3e067d2d (diff) | |
download | ghostpdl-eec6fd158ee477facfb4bf9edd4e99506c195732.tar.gz |
Pacify helgrind so that gs_heap_status is thread safe.
The 'heap_available' is documented as a 'snapshot', but is not a
thead risk. This change locks around the collection of the info to
be returned in the gs_memory_status structure.
Diffstat (limited to 'base/gsmalloc.c')
-rw-r--r-- | base/gsmalloc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/base/gsmalloc.c b/base/gsmalloc.c index 58047c9b0..46af25d63 100644 --- a/base/gsmalloc.c +++ b/base/gsmalloc.c @@ -450,17 +450,23 @@ gs_heap_stable(gs_memory_t *mem) /* * NB: In a multi-threaded application, this is only a 'snapshot' * since other threads may change the heap_status. The heap_available() - * probe is just an approximation anyway. + * probe is just an approximation anyway. To pacify helgrind, we lock + * around the modificatons to the gs_memory_status that is returned. */ static void gs_heap_status(gs_memory_t * mem, gs_memory_status_t * pstat) { gs_malloc_memory_t *mmem = (gs_malloc_memory_t *) mem; + long avail_snapshot = heap_available(); - pstat->allocated = mmem->used + heap_available(); + if (mmem->monitor) + gx_monitor_enter(mmem->monitor); + pstat->allocated = mmem->used + avail_snapshot; pstat->used = mmem->used; pstat->max_used = mmem->max_used; pstat->is_thread_safe = true; /* this allocator has a mutex (monitor) and IS thread safe */ + if (mmem->monitor) + gx_monitor_leave(mmem->monitor); /* Done with exclusive access */ } static void gs_heap_enable_free(gs_memory_t * mem, bool enable) |