summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2020-02-06 13:02:33 +0000
committerRobin Watts <Robin.Watts@artifex.com>2020-02-06 13:25:48 +0000
commitd185c5afea23e937edda368491d382650001f5b4 (patch)
treeb5dbc84bc5dcee0b55a4a5c97906e65ef317f949
parentf40471ba6312a89cda81c23c1690dfbdbbc2722f (diff)
downloadghostpdl-d185c5afea23e937edda368491d382650001f5b4.tar.gz
Memento: Remove MEMENTO_SQUEEZE_BUILD from the code.
Rather than relying on building with MEMENTO_SQUEEZE_BUILD, instead nobble the pthread based threading functions themselves to check Memento_squeezing in MEMENTO builds. a) This means less pollution of the code overall as the changes are restricted to just one module. b) This will stop me forgetting to build with MEMENTO_SQUEEZE_BUILD and not understanding the results - EVERY SINGLE TIME. c) It means a single MEMENTO build can be used both for memory squeezing (of single-threaded runs) and normal memento testing (of both single- and multi-threaded runs).
-rw-r--r--base/gp_psync.c76
-rw-r--r--base/gsicc_cache.c56
-rw-r--r--base/gsicc_lcms2.c2
-rw-r--r--base/gsicc_lcms2mt.c2
-rw-r--r--base/gsicc_manage.c12
-rw-r--r--base/gslibctx.c12
-rw-r--r--base/gsmalloc.c2
-rw-r--r--base/memento.c10
-rw-r--r--base/memento.h3
-rw-r--r--base/sjpx_openjpeg.c15
-rw-r--r--psi/imain.c7
11 files changed, 73 insertions, 124 deletions
diff --git a/base/gp_psync.c b/base/gp_psync.c
index eebefa1d6..3a7d6a4dd 100644
--- a/base/gp_psync.c
+++ b/base/gp_psync.c
@@ -66,10 +66,15 @@ gp_semaphore_open(gp_semaphore * sema)
pt_semaphore_t * const sem = (pt_semaphore_t *)sema;
int scode;
-#ifdef MEMENTO_SQUEEZE_BUILD
- eprintf("Can't create semaphores when memory squeezing with forks\n");
- Memento_bt();
- return_error(gs_error_VMerror);
+#ifdef MEMENTO
+ if (Memento_squeezing()) {
+ /* If squeezing, we nobble all the locking functions to do nothing.
+ * We also ensure we never actually create threads (elsewhere),
+ * so this is still safe. */
+ memset(&sem->mutex, 0, sizeof(sem->mutex));
+ memset(&sem->cond, 0, sizeof(sem->cond));
+ return 0;
+ }
#endif
if (!sema)
@@ -93,6 +98,11 @@ gp_semaphore_close(gp_semaphore * sema)
pt_semaphore_t * const sem = (pt_semaphore_t *)sema;
int scode, scode2;
+#ifdef MEMENTO
+ if (Memento_squeezing())
+ return 0;
+#endif
+
scode = pthread_cond_destroy(&sem->cond);
scode2 = pthread_mutex_destroy(&sem->mutex);
if (scode == 0)
@@ -106,10 +116,13 @@ gp_semaphore_wait(gp_semaphore * sema)
pt_semaphore_t * const sem = (pt_semaphore_t *)sema;
int scode, scode2;
-#ifdef MEMENTO_SQUEEZE_BUILD
- eprintf("Can't create mutexes when memory squeezing with forks\n");
- Memento_bt();
- return_error(gs_error_VMerror);
+#ifdef MEMENTO
+ if (Memento_squeezing()) {
+ /* If squeezing, we nobble all the locking functions to do nothing.
+ * We also ensure we never actually create threads (elsewhere),
+ * so this is still safe. */
+ return 0;
+ }
#endif
scode = pthread_mutex_lock(&sem->mutex);
@@ -134,6 +147,11 @@ gp_semaphore_signal(gp_semaphore * sema)
pt_semaphore_t * const sem = (pt_semaphore_t *)sema;
int scode, scode2;
+#ifdef MEMENTO
+ if (Memento_squeezing())
+ return 0;
+#endif
+
scode = pthread_mutex_lock(&sem->mutex);
if (scode != 0)
return SEM_ERROR_CODE(scode);
@@ -178,15 +196,15 @@ gp_monitor_open(gp_monitor * mona)
pthread_mutexattr_t attr;
pthread_mutexattr_t *attrp = NULL;
-#ifdef MEMENTO_SQUEEZE_BUILD
- eprintf("Can't create monitors when memory squeezing with forks\n");
- Memento_bt();
- return_error(gs_error_VMerror);
-#endif
-
if (!mona)
return -1; /* monitors are not movable */
+#ifdef MEMENTO
+ if (Memento_squeezing()) {
+ memset(mona, 0, sizeof(*mona));
+ return 0;
+ }
+#endif
#ifdef GS_RECURSIVE_MUTEXATTR
attrp = &attr;
@@ -216,6 +234,11 @@ gp_monitor_close(gp_monitor * mona)
pthread_mutex_t * const mon = &((gp_pthread_recursive_t *)mona)->mutex;
int scode;
+#ifdef MEMENTO
+ if (Memento_squeezing())
+ return 0;
+#endif
+
scode = pthread_mutex_destroy(mon);
return SEM_ERROR_CODE(scode);
}
@@ -226,6 +249,12 @@ gp_monitor_enter(gp_monitor * mona)
pthread_mutex_t * const mon = (pthread_mutex_t *)mona;
int scode;
+#ifdef MEMENTO
+ if (Memento_squeezing()) {
+ return 0;
+ }
+#endif
+
#ifdef GS_RECURSIVE_MUTEXATTR
scode = pthread_mutex_lock(mon);
#else
@@ -256,6 +285,11 @@ gp_monitor_leave(gp_monitor * mona)
pthread_mutex_t * const mon = (pthread_mutex_t *)mona;
int scode = 0;
+#ifdef MEMENTO
+ if (Memento_squeezing())
+ return 0;
+#endif
+
#ifdef GS_RECURSIVE_MUTEXATTR
scode = pthread_mutex_unlock(mon);
#else
@@ -303,18 +337,20 @@ gp_thread_begin_wrapper(void *thread_data /* gp_thread_creation_closure_t * */)
int
gp_create_thread(gp_thread_creation_callback_t proc, void *proc_data)
{
- gp_thread_creation_closure_t *closure =
- (gp_thread_creation_closure_t *)malloc(sizeof(*closure));
+ gp_thread_creation_closure_t *closure;
pthread_t ignore_thread;
pthread_attr_t attr;
int code;
-#ifdef MEMENTO_SQUEEZE_BUILD
- eprintf("Can't create threads when memory squeezing with forks\n");
- Memento_bt();
- return_error(gs_error_VMerror);
+#ifdef MEMENTO
+ if (Memento_squeezing()) {
+ eprintf("Can't create threads when memory squeezing with forks\n");
+ Memento_bt();
+ return_error(gs_error_VMerror);
+ }
#endif
+ closure = (gp_thread_creation_closure_t *)malloc(sizeof(*closure));
if (!closure)
return_error(gs_error_VMerror);
closure->proc = proc;
diff --git a/base/gsicc_cache.c b/base/gsicc_cache.c
index b5c2a4415..b69b281ff 100644
--- a/base/gsicc_cache.c
+++ b/base/gsicc_cache.c
@@ -108,9 +108,6 @@ gsicc_cache_new(gs_memory_t *memory)
result->num_links = 0;
result->cache_full = false;
result->memory = memory->stable_memory;
-#ifdef MEMENTO_SQUEEZE_BUILD
- result->lock = NULL;
-#else
result->lock = gx_monitor_label(gx_monitor_alloc(memory->stable_memory),
"gsicc_cache_new");
if (result->lock == NULL) {
@@ -124,7 +121,6 @@ gsicc_cache_new(gs_memory_t *memory)
gs_free_object(memory->stable_memory, result, "gsicc_cache_new");
return(NULL);
}
-#endif
rc_init_free(result, memory->stable_memory, 1, rc_gsicc_link_cache_free);
if_debug2m(gs_debug_flag_icc, memory,
"[icc] Allocating link cache = 0x%p memory = 0x%p\n",
@@ -165,12 +161,10 @@ icc_linkcache_finalize(const gs_memory_t *mem, void *ptr)
}
#endif
if (link_cache->rc.ref_count == 0) {
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_free(link_cache->lock);
link_cache->lock = NULL;
gx_semaphore_free(link_cache->full_wait);
link_cache->full_wait = 0;
-#endif
}
}
@@ -190,7 +184,6 @@ gsicc_alloc_link_dev(gs_memory_t *memory, cmm_profile_t *src_profile,
if (result == NULL)
return NULL;
-#ifndef MEMENTO_SQUEEZE_BUILD
result->lock = gx_monitor_label(gx_monitor_alloc(memory->stable_memory),
"gsicc_link_new");
if (result->lock == NULL) {
@@ -198,7 +191,6 @@ gsicc_alloc_link_dev(gs_memory_t *memory, cmm_profile_t *src_profile,
return NULL;
}
gx_monitor_enter(result->lock);
-#endif
/* set up placeholder values */
result->is_monitored = false;
@@ -283,7 +275,6 @@ gsicc_alloc_link(gs_memory_t *memory, gsicc_hashlink_t hashcode)
"gsicc_alloc_link");
if (result == NULL)
return NULL;
-#ifndef MEMENTO_SQUEEZE_BUILD
result->lock = gx_monitor_label(gx_monitor_alloc(memory->stable_memory),
"gsicc_link_new");
if (result->lock == NULL) {
@@ -291,7 +282,6 @@ gsicc_alloc_link(gs_memory_t *memory, gsicc_hashlink_t hashcode)
return NULL;
}
gx_monitor_enter(result->lock); /* this link is owned by this thread until built and made "valid" */
-#endif
/* set up placeholder values */
result->is_monitored = false;
result->orig_procs.map_buffer = NULL;
@@ -324,9 +314,7 @@ gsicc_set_link_data(gsicc_link_t *icc_link, void *link_handle,
bool includes_softproof, bool includes_devlink,
bool pageneutralcolor, gsicc_colorbuffer_t data_cs)
{
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter(lock); /* lock the cache while changing data */
-#endif
icc_link->link_handle = link_handle;
gscms_get_link_dim(link_handle, &(icc_link->num_input), &(icc_link->num_output),
icc_link->memory);
@@ -349,20 +337,16 @@ gsicc_set_link_data(gsicc_link_t *icc_link, void *link_handle,
/* release the lock of the link so it can now be used */
icc_link->valid = true;
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(icc_link->lock);
gx_monitor_leave(lock); /* done with updating, let everyone run */
-#endif
}
static void
gsicc_link_free_contents(gsicc_link_t *icc_link)
{
icc_link->procs.free_link(icc_link);
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_free(icc_link->lock);
icc_link->lock = NULL;
-#endif
}
void
@@ -514,9 +498,7 @@ gsicc_findcachelink(gsicc_hashlink_t hash, gsicc_link_cache_t *icc_link_cache,
int64_t hashcode = hash.link_hashcode;
/* Look through the cache for the hashcode */
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter(icc_link_cache->lock);
-#endif
/* List scanning is fast, so we scan the entire list, this includes */
/* links that are currently unused, but still in the cache (zero_ref) */
@@ -540,7 +522,6 @@ gsicc_findcachelink(gsicc_hashlink_t hash, gsicc_link_cache_t *icc_link_cache,
if_debug3m('^', curr->memory, "[^]%s 0x%p ++ => %d\n",
"icclink", curr, curr->ref_count);
while (curr->valid == false) {
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(icc_link_cache->lock); /* exit to let other threads run briefly */
gx_monitor_enter(curr->lock); /* wait until we can acquire the lock */
gx_monitor_leave(curr->lock); /* it _should be valid now */
@@ -551,19 +532,14 @@ gsicc_findcachelink(gsicc_hashlink_t hash, gsicc_link_cache_t *icc_link_cache,
emprintf1(curr->memory, "link 0x%p lock released, but still not valid.\n", curr); /* Breakpoint here */
}
gx_monitor_enter(icc_link_cache->lock); /* re-enter to loop and check */
-#endif
}
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(icc_link_cache->lock);
-#endif
return(curr); /* success */
}
prev = curr;
curr = curr->next;
}
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(icc_link_cache->lock);
-#endif
return NULL;
}
@@ -578,9 +554,7 @@ gsicc_remove_link(gsicc_link_t *link, const gs_memory_t *memory)
"[icc] Removing link = 0x%p memory = 0x%p\n", link,
memory->stable_memory);
/* NOTE: link->ref_count must be 0: assert ? */
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter(icc_link_cache->lock);
-#endif
if (link->ref_count != 0) {
emprintf2(memory, "link at 0x%p being removed, but has ref_count = %d\n", link, link->ref_count);
}
@@ -604,19 +578,15 @@ gsicc_remove_link(gsicc_link_t *link, const gs_memory_t *memory)
/* use it (ref_count > 0). Skip freeing it if so. */
if (curr == link && link->ref_count == 0) {
icc_link_cache->num_links--; /* no longer in the cache */
-#ifndef MEMENTO_SQUEEZE_BUILD
if (icc_link_cache->cache_full) {
icc_link_cache->cache_full = false;
gx_semaphore_signal(icc_link_cache->full_wait); /* let a waiting thread run */
}
gx_monitor_leave(icc_link_cache->lock);
-#endif
gsicc_link_free(link, memory); /* outside link cache now. */
} else {
/* even if we didn't find the link to remove, unlock the cache */
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(icc_link_cache->lock);
-#endif
}
}
@@ -874,9 +844,7 @@ gsicc_alloc_link_entry(gsicc_link_cache_t *icc_link_cache,
*ret_link = NULL;
/* First see if we can add a link */
/* TODO: this should be based on memory usage, not just num_links */
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter(icc_link_cache->lock);
-#endif
while (icc_link_cache->num_links >= ICC_CACHE_MAXLINKS) {
/* Look through the cache for first zero ref count to re-use that entry.
When ref counts go to zero, the icc_link will have been moved to
@@ -897,12 +865,10 @@ gsicc_alloc_link_entry(gsicc_link_cache_t *icc_link_cache,
link = link->next;
}
if (link == NULL) {
-#ifndef MEMENTO_SQUEEZE_BUILD
icc_link_cache->cache_full = true;
/* unlock while waiting for a link to come available */
gx_monitor_leave(icc_link_cache->lock);
gx_semaphore_wait(icc_link_cache->full_wait);
-#endif
/* repeat the findcachelink to see if some other thread has */
/* already started building the link we need */
*ret_link = gsicc_findcachelink(hash, icc_link_cache,
@@ -911,9 +877,7 @@ gsicc_alloc_link_entry(gsicc_link_cache_t *icc_link_cache,
if (*ret_link != NULL)
return true;
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter(icc_link_cache->lock); /* restore the lock */
-#endif
} else {
/* Remove the zero ref_count link profile we found. */
/* Even if we remove this link, we may still be maxed out so*/
@@ -934,10 +898,8 @@ gsicc_alloc_link_entry(gsicc_link_cache_t *icc_link_cache,
icc_link_cache->head = *ret_link;
icc_link_cache->num_links++;
}
-#ifndef MEMENTO_SQUEEZE_BUILD
/* unlock before returning */
gx_monitor_leave(icc_link_cache->lock);
-#endif
return false; /* we didn't find it, but return a link to be filled */
}
@@ -1154,10 +1116,8 @@ gsicc_get_link_profile(const gs_gstate *pgs, gx_device *dev,
proof_profile->buffer_size,
memory);
proof_profile->profile_handle = cms_proof_profile;
-#if !defined(MEMENTO_SQUEEZE_BUILD)
if (!gscms_is_threadsafe())
gx_monitor_enter(proof_profile->lock);
-#endif
} else {
/* Cant create the link */
gsicc_remove_link(link, cache_mem);
@@ -1174,10 +1134,8 @@ gsicc_get_link_profile(const gs_gstate *pgs, gx_device *dev,
devlink_profile->buffer_size,
memory);
devlink_profile->profile_handle = cms_devlink_profile;
-#if !defined(MEMENTO_SQUEEZE_BUILD)
if (!gscms_is_threadsafe())
gx_monitor_enter(devlink_profile->lock);
-#endif
} else {
/* Cant create the link */
gsicc_remove_link(link, cache_mem);
@@ -1185,7 +1143,6 @@ gsicc_get_link_profile(const gs_gstate *pgs, gx_device *dev,
}
}
}
-#if !defined(MEMENTO_SQUEEZE_BUILD)
/* Profile reading of same structure not thread safe in CMM */
if (!gscms_is_threadsafe()) {
gx_monitor_enter(gs_input_profile->lock);
@@ -1193,7 +1150,6 @@ gsicc_get_link_profile(const gs_gstate *pgs, gx_device *dev,
gx_monitor_enter(gs_output_profile->lock);
}
}
-#endif
/* We may have to worry about special handling for DeviceGray to
DeviceCMYK to ensure that Gray is mapped to K only. This is only
done once and then it is cached and the link used. Note that Adobe
@@ -1235,7 +1191,6 @@ gsicc_get_link_profile(const gs_gstate *pgs, gx_device *dev,
rendering_params,
src_dev_link, cms_flags,
cache_mem->non_gc_memory);
-#if !defined(MEMENTO_SQUEEZE_BUILD)
if (!gscms_is_threadsafe()) {
if (include_softproof) {
gx_monitor_leave(proof_profile->lock);
@@ -1244,20 +1199,17 @@ gsicc_get_link_profile(const gs_gstate *pgs, gx_device *dev,
gx_monitor_leave(devlink_profile->lock);
}
}
-#endif
} else {
link_handle = gscms_get_link(cms_input_profile, cms_output_profile,
rendering_params, cms_flags,
cache_mem->non_gc_memory);
}
-#if !defined(MEMENTO_SQUEEZE_BUILD)
if (!gscms_is_threadsafe()) {
if (!src_dev_link) {
gx_monitor_leave(gs_output_profile->lock);
}
gx_monitor_leave(gs_input_profile->lock);
}
-#endif
if (link_handle != NULL) {
if (gs_input_profile->data_cs == gsGRAY)
pageneutralcolor = false;
@@ -1284,13 +1236,11 @@ gsicc_get_link_profile(const gs_gstate *pgs, gx_device *dev,
if_debug2m('^', link->memory, "[^]icclink 0x%p -- => %d\n",
link, link->ref_count);
-#ifndef MEMENTO_SQUEEZE_BUILD
if (icc_link_cache->cache_full) {
icc_link_cache->cache_full = false;
gx_semaphore_signal(icc_link_cache->full_wait); /* let a waiting thread run */
}
gx_monitor_leave(link->lock);
-#endif
gsicc_remove_link(link, cache_mem);
return NULL;
}
@@ -1778,9 +1728,7 @@ gsicc_release_link(gsicc_link_t *icclink)
icc_link_cache = icclink->icc_link_cache;
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter(icc_link_cache->lock);
-#endif
if_debug2m('^', icclink->memory, "[^]icclink 0x%p -- => %d\n",
icclink, icclink->ref_count - 1);
/* Decrement the reference count */
@@ -1818,17 +1766,13 @@ gsicc_release_link(gsicc_link_t *icclink)
prev->next = icclink;
icclink->next = curr;
}
-#ifndef MEMENTO_SQUEEZE_BUILD
/* Finally, if some thread was waiting because the cache was full, let it run */
if (icc_link_cache->cache_full) {
icc_link_cache->cache_full = false;
gx_semaphore_signal(icc_link_cache->full_wait); /* let a waiting thread run */
}
-#endif
}
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(icc_link_cache->lock);
-#endif
}
/* Used to initialize the buffer description prior to color conversion */
diff --git a/base/gsicc_lcms2.c b/base/gsicc_lcms2.c
index 3428d4ffc..2fc3645c6 100644
--- a/base/gsicc_lcms2.c
+++ b/base/gsicc_lcms2.c
@@ -25,9 +25,7 @@
#include "gsicc_cms.h"
#include "gxdevice.h"
-#ifndef MEMENTO_SQUEEZE_BUILD
#define USE_LCMS2_LOCKING
-#endif
#ifdef USE_LCMS2_LOCKING
#include "gxsync.h"
diff --git a/base/gsicc_lcms2mt.c b/base/gsicc_lcms2mt.c
index 1748b16d1..ec65fec72 100644
--- a/base/gsicc_lcms2mt.c
+++ b/base/gsicc_lcms2mt.c
@@ -29,9 +29,7 @@
#include "cal.h"
#endif
-#ifndef MEMENTO_SQUEEZE_BUILD
#define USE_LCMS2_LOCKING
-#endif
#ifdef USE_LCMS2_LOCKING
#include "gxsync.h"
diff --git a/base/gsicc_manage.c b/base/gsicc_manage.c
index 71e5e4761..9357f5e06 100644
--- a/base/gsicc_manage.c
+++ b/base/gsicc_manage.c
@@ -550,20 +550,14 @@ void
gsicc_adjust_profile_rc(cmm_profile_t *profile_data, int delta, const char *name_str)
{
if (profile_data != NULL) {
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter(profile_data->lock);
-#endif
if (profile_data->rc.ref_count == 1 && delta < 0) {
profile_data->rc.ref_count = 0; /* while locked */
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(profile_data->lock);
-#endif
rc_free_struct(profile_data, name_str);
} else {
rc_adjust(profile_data, delta, name_str);
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave(profile_data->lock);
-#endif
}
}
}
@@ -2158,9 +2152,6 @@ gsicc_profile_new(stream *s, gs_memory_t *memory, const char* pname,
result->v2_size = 0;
result->release = gscms_release_profile; /* Default case */
-#ifdef MEMENTO_SQUEEZE_BUILD
- result->lock = NULL;
-#else
result->lock = gx_monitor_label(gx_monitor_alloc(mem_nongc),
"gsicc_manage");
if (result->lock == NULL) {
@@ -2168,7 +2159,6 @@ gsicc_profile_new(stream *s, gs_memory_t *memory, const char* pname,
gs_free_object(mem_nongc, nameptr, "gsicc_profile_new");
return NULL;
}
-#endif
if_debug1m(gs_debug_flag_icc, mem_nongc,
"[icc] allocating ICC profile = 0x%p\n", result);
return result;
@@ -2202,12 +2192,10 @@ rc_free_icc_profile(gs_memory_t * mem, void *ptr_in, client_name_t cname)
profile->name_length = 0;
}
profile->hash_is_valid = 0;
-#ifndef MEMENTO_SQUEEZE_BUILD
if (profile->lock != NULL) {
gx_monitor_free(profile->lock);
profile->lock = NULL;
}
-#endif
/* If we had a DeviceN profile with names deallocate that now */
if (profile->spotnames != NULL) {
/* Free the linked list in this object */
diff --git a/base/gslibctx.c b/base/gslibctx.c
index 133f822bf..7cc0b4517 100644
--- a/base/gslibctx.c
+++ b/base/gslibctx.c
@@ -262,14 +262,10 @@ int gs_lib_ctx_init(gs_lib_ctx_t *ctx, gs_memory_t *mem)
memset(pio, 0, sizeof(*pio));
if (ctx != NULL) {
-#ifdef MEMENTO_SQUEEZE_BUILD
- goto Failure;
-#else
pio->core = ctx->core;
gx_monitor_enter((gx_monitor_t *)(pio->core->monitor));
pio->core->refs++;
gx_monitor_leave((gx_monitor_t *)(pio->core->monitor));
-#endif /* MEMENTO_SQUEEZE_BUILD */
} else {
pio->core = (gs_lib_ctx_core_t *)gs_alloc_bytes_immovable(mem,
sizeof(gs_lib_ctx_core_t),
@@ -305,7 +301,6 @@ int gs_lib_ctx_init(gs_lib_ctx_t *ctx, gs_memory_t *mem)
pio->core->fs->memory = mem;
pio->core->fs->next = NULL;
-#ifndef MEMENTO_SQUEEZE_BUILD
pio->core->monitor = gx_monitor_alloc(mem);
if (pio->core->monitor == NULL) {
#ifdef WITH_CAL
@@ -316,7 +311,6 @@ int gs_lib_ctx_init(gs_lib_ctx_t *ctx, gs_memory_t *mem)
gs_free_object(mem, pio, "gs_lib_ctx_init");
return -1;
}
-#endif /* MEMENTO_SQUEEZE_BUILD */
pio->core->refs = 1;
pio->core->memory = mem;
@@ -414,17 +408,11 @@ void gs_lib_ctx_fin(gs_memory_t *mem)
mem_err_print = NULL;
#endif
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_enter((gx_monitor_t *)(ctx->core->monitor));
-#endif
refs = --ctx->core->refs;
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_leave((gx_monitor_t *)(ctx->core->monitor));
-#endif
if (refs == 0) {
-#ifndef MEMENTO_SQUEEZE_BUILD
gx_monitor_free((gx_monitor_t *)(ctx->core->monitor));
-#endif
#ifdef WITH_CAL
cal_fin(ctx->core->cal_ctx, ctx->core->memory);
#endif
diff --git a/base/gsmalloc.c b/base/gsmalloc.c
index 4a2c2c20a..52998b17e 100644
--- a/base/gsmalloc.c
+++ b/base/gsmalloc.c
@@ -127,13 +127,11 @@ gs_malloc_memory_init(void)
mem->thread_safe_memory = (gs_memory_t *)mem; /* this allocator is thread safe */
/* Allocate a monitor to serialize access to structures within */
mem->monitor = NULL; /* prevent use during initial allocation */
-#ifndef MEMENTO_SQUEEZE_BUILD
mem->monitor = gx_monitor_label(gx_monitor_alloc((gs_memory_t *)mem), "heap");
if (mem->monitor == NULL) {
free(mem);
return NULL;
}
-#endif
return mem;
}
diff --git a/base/memento.c b/base/memento.c
index 3098b00d4..e11603b50 100644
--- a/base/memento.c
+++ b/base/memento.c
@@ -2895,6 +2895,11 @@ void Memento_stopLeaking(void)
memento.leaking--;
}
+int Memento_squeezing(void)
+{
+ return memento.squeezing;
+}
+
#endif /* MEMENTO_CPP_EXTRAS_ONLY */
#ifdef __cplusplus
@@ -3094,4 +3099,9 @@ void (Memento_stopLeaking)(void)
{
}
+int (Memento_squeezing)(void)
+{
+ return 0;
+}
+
#endif
diff --git a/base/memento.h b/base/memento.h
index e81db0783..b822479f9 100644
--- a/base/memento.h
+++ b/base/memento.h
@@ -261,6 +261,8 @@ void Memento_stopLeaking(void);
int Memento_sequence(void);
+int Memento_squeezing(void);
+
void Memento_fin(void);
void Memento_bt(void);
@@ -322,6 +324,7 @@ void Memento_bt(void);
#define Memento_fin() do {} while (0)
#define Memento_bt() do {} while (0)
#define Memento_sequence() (0)
+#define Memento_squeezing() (0)
#endif /* MEMENTO */
diff --git a/base/sjpx_openjpeg.c b/base/sjpx_openjpeg.c
index 6861a9caf..a4d7884ef 100644
--- a/base/sjpx_openjpeg.c
+++ b/base/sjpx_openjpeg.c
@@ -38,20 +38,16 @@ int sjpxd_create(gs_memory_t *mem)
#if !defined(SHARE_JPX) || (SHARE_JPX == 0)
gs_lib_ctx_t *ctx = mem->gs_lib_ctx;
-#ifdef MEMENTO_SQUEEZE_BUILD
- ctx->sjpxd_private = NULL;
-#else
ctx->sjpxd_private = gx_monitor_label(gx_monitor_alloc(mem), "sjpxd_monitor");
if (ctx->sjpxd_private == NULL)
return gs_error_VMerror;
#endif
-#endif
return 0;
}
void sjpxd_destroy(gs_memory_t *mem)
{
-#if (!defined(SHARE_JPX) || (SHARE_JPX == 0)) && !defined(MEMENTO_SQUEEZE_BUILD)
+#if !defined(SHARE_JPX) || (SHARE_JPX == 0)
gs_lib_ctx_t *ctx = mem->gs_lib_ctx;
gx_monitor_free((gx_monitor_t *)ctx->sjpxd_private);
@@ -64,13 +60,9 @@ static int opj_lock(gs_memory_t *mem)
#if !defined(SHARE_JPX) || (SHARE_JPX == 0)
int ret;
-#ifdef MEMENTO_SQUEEZE_BUILD
- ret = 0;
-#else
gs_lib_ctx_t *ctx = mem->gs_lib_ctx;
ret = gx_monitor_enter((gx_monitor_t *)ctx->sjpxd_private);
-#endif
assert(opj_memory == NULL);
opj_memory = mem->non_gc_memory;
return ret;
@@ -86,12 +78,7 @@ static int opj_unlock(gs_memory_t *mem)
assert(opj_memory != NULL);
opj_memory = NULL;
-#ifdef MEMENTO_SQUEEZE_BUILD
- (void)ctx;
- return 0;
-#else
return gx_monitor_leave((gx_monitor_t *)ctx->sjpxd_private);
-#endif
#else
return 0;
#endif
diff --git a/psi/imain.c b/psi/imain.c
index 95ef5b6bd..62130e824 100644
--- a/psi/imain.c
+++ b/psi/imain.c
@@ -1140,11 +1140,10 @@ gs_main_finit(gs_main_instance * minst, int exit_status, int code)
else {
emprintf1(imemory, "UNKNOWN ERROR %d reclaiming the memory while the interpreter finalization.\n", code);
}
-#ifdef MEMENTO_SQUEEZE_BUILD
- if (code != gs_error_VMerror ) return gs_error_Fatal;
-#else
- return gs_error_Fatal;
+#ifdef MEMENTO
+ if (Memento_squeezing() && code != gs_error_VMerror ) return gs_error_Fatal;
#endif
+ return gs_error_Fatal;
}
i_ctx_p = minst->i_ctx_p; /* interp_reclaim could change it. */
}