diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2021-10-27 17:54:20 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2021-11-05 14:32:19 +0000 |
commit | 91e29d42a601689f13e9202fc6b582d53901fbc2 (patch) | |
tree | 7a8526c18f050af408749cc587a49a0ca13b1474 /contrib | |
parent | 6dd05a013f66a9322f92f62fd2d46be9bfa82097 (diff) | |
download | ghostpdl-91e29d42a601689f13e9202fc6b582d53901fbc2.tar.gz |
Runtime safety of non threadsafe devices and rework globals.
Some devices within Ghostscript (currently the x11 devices,
uniprint and opvp/oprp) use non const static variables, so cannot
be run in multiple instances at a time.
We now maintain a core "count" of how many non-threadsafe devices are
being used at any time. This value can be atomically adjusted by calls
to gs_lib_ctx_nts_adjust.
Non threadsafe devices now call gx_init_non_threadsafe_device either
as or as part of their initialise_device proc. This function attempts
to increment the non-threadsafe count and fails to init if there is
already a non-threadsafe device running.
On success, the device finalize method is modified so that it will
decrement the count at the end.
The known non-threadsafe devices are updated to call this.
In order to have somewhere safe to store this count, we introduce
a gs_globals structure, shared between instances. Setting this up
without race conditions requires some new gp_ functions that can
make use of platform specific threading primitives. We have these
implemented for both windows and pthread based platforms. On other
platforms, we drop back to the old unsafe mechanism for counting
instances.
While we do this work, we take the opportunity to push the
gs_memory_t pointer used for non-threadsafe debug printing into thread
local storage.
This enables us to remove the remaining GS_THREADSAFE guarded
compilation from the source code. What is left is broadly down to
allowing debugging collection for statistics, and these are now
controlled by specific COLLECT_STATS_XXX defines. It is assumed
that anyone wanting to collect such stats is smart enough to not
try to do so while using Ghostscript in a multi-instance environment.
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/opvp/gdevopvp.c | 2 | ||||
-rw-r--r-- | contrib/pcl3/eprn/mediasize.c | 8 | ||||
-rw-r--r-- | contrib/pcl3/src/pclcap.c | 11 |
3 files changed, 12 insertions, 9 deletions
diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c index 844b46cd3..aab8a6384 100644 --- a/contrib/opvp/gdevopvp.c +++ b/contrib/opvp/gdevopvp.c @@ -301,6 +301,7 @@ opvp_initialize_device_procs(gx_device *dev) { gdev_prn_initialize_device_procs(dev); + set_dev_proc(dev, initialize_device, gx_init_non_threadsafe_device); set_dev_proc(dev, open_device, opvp_open); set_dev_proc(dev, get_initial_matrix, opvp_get_initial_matrix); set_dev_proc(dev, output_page, opvp_output_page); @@ -381,6 +382,7 @@ oprp_initialize_device_procs(gx_device *dev) { gdev_prn_initialize_device_procs(dev); + set_dev_proc(dev, initialize_device, gx_init_non_threadsafe_device); set_dev_proc(dev, open_device, oprp_open); set_dev_proc(dev, output_page, opvp_output_page); set_dev_proc(dev, close_device, opvp_close); diff --git a/contrib/pcl3/eprn/mediasize.c b/contrib/pcl3/eprn/mediasize.c index c9e3d41f7..1bdde2a46 100644 --- a/contrib/pcl3/eprn/mediasize.c +++ b/contrib/pcl3/eprn/mediasize.c @@ -149,7 +149,9 @@ static const ms_SizeDescription list[] = { /*****************************************************************************/ -#if !defined(NDEBUG) && !defined(GS_THREADSAFE) +#undef CHECK_CONSTRAINTS + +#ifdef CHECK_CONSTRAINTS static char checked = 0; /* Function to check constraints on table entries */ @@ -183,9 +185,9 @@ static void check(void) const ms_SizeDescription *ms_find_size_from_code(ms_MediaCode code) { -#if !defined(NDEBUG) && !defined(GS_THREADSAFE) +#ifdef CHECK_CONSTRAINTS if (!checked) check(); -#endif /* !NDEBUG && !GS_THREADSAFE */ +#endif code = ms_without_flags(code); if (code < 1 || array_size(list) <= code) return NULL; diff --git a/contrib/pcl3/src/pclcap.c b/contrib/pcl3/src/pclcap.c index 77f52aa89..56fd0c3dc 100644 --- a/contrib/pcl3/src/pclcap.c +++ b/contrib/pcl3/src/pclcap.c @@ -783,9 +783,9 @@ const pcl_PrinterDescription pcl3_printers[] = { }; /*****************************************************************************/ +#undef CHECK_CONSTRAINTS -#if !defined(NDEBUG) && !defined(GS_THREADSAFE) - +#ifdef CHECK_CONSTRAINTS static int checked = 0; static void check(void) @@ -800,8 +800,7 @@ static void check(void) return; } - -#endif /* !NDEBUG && !GS_THREADSAFE */ +#endif /****************************************************************************** @@ -816,9 +815,9 @@ static void check(void) void pcl3_fill_defaults(pcl_Printer printer, pcl_FileData *data) { -#if !defined(NDEBUG) && !defined(GS_THREADSAFE) +#ifdef CHECK_CONSTRAINTS if (!checked) check(); -#endif /* !NDEBUG */ +#endif /* Set everything to zero */ memset(data, 0, sizeof(pcl_FileData)); |