summaryrefslogtreecommitdiff
path: root/base/gsicc_nocm.c
diff options
context:
space:
mode:
authorRay Johnston <ray.johnston@artifex.com>2018-02-16 13:51:04 -0800
committerRay Johnston <ray.johnston@artifex.com>2018-03-28 22:08:40 -0700
commit9ff6b34e461fcbd4ef27fbb6c5c8a15071fe1370 (patch)
tree6996747ec44f0f2946bdb880369d942c70920652 /base/gsicc_nocm.c
parent33701ac07115cb2f634a40ab73a5c127ca870ad8 (diff)
downloadghostpdl-9ff6b34e461fcbd4ef27fbb6c5c8a15071fe1370.tar.gz
Make ICC profile management thread safe.
The change to ref_count of profiles needs to be protected by a lock if the profile ref_count could be changed by another thread. Also when decrementing the ref_count to 0, we cannot free the lock until after the profile has been unlocked. New routine gsicc_adjust_profile_rc replaces old (not threadsafe) function gsicc_profile_reference. Also add tracing "cname" to the RC_ADJUST_ macro to aid in debugging with -Z^ debug flag. Testing had revealed race conditions which are now fixed (eliminate use of semaphores). This also changes the gsicc_lcms2art.c interface functions to keep a list of transforms configured to have differing buffer formats that include alpha, planar IN/OUT, big_endian IN/OUT, bytes_per_component IN/OUT which are cloned as needed by threads. Change gscms_is_threadsafe to return "true" in gsicc_lcms2art.c TBD: If a link fails to build a thread may hang waiting for the link profile to become valid if it was not the thread that was building it. Not a new condition, but exposed when gscms_is_threadsafe returns true. TBD: Fix error handling / clean-up when links fail to build. Also not new, but is needed to prevent leaks, and possibly hang conditions.
Diffstat (limited to 'base/gsicc_nocm.c')
-rw-r--r--base/gsicc_nocm.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/base/gsicc_nocm.c b/base/gsicc_nocm.c
index ea24e9fc7..4f0c0f67e 100644
--- a/base/gsicc_nocm.c
+++ b/base/gsicc_nocm.c
@@ -389,8 +389,7 @@ gsicc_nocm_get_link(const gs_gstate *pgs, gx_device *dev,
return NULL;
/* Now compute the link contents */
- /* Lock the cache as we alter the procs */
- gx_monitor_enter(pgs->icc_link_cache->lock);
+ /* We (this thread) owns the lock on the new link just created. */
result->procs.map_buffer = gsicc_nocm_transform_color_buffer;
result->procs.map_color = gsicc_nocm_transform_color;
@@ -437,7 +436,6 @@ gsicc_nocm_get_link(const gs_gstate *pgs, gx_device *dev,
} else {
result->is_identity = false;
}
- result->valid = true;
if (nocm_link->num_in == 4)
data_cs = gsCMYK;
else if (nocm_link->num_in == 1)
@@ -448,13 +446,9 @@ gsicc_nocm_get_link(const gs_gstate *pgs, gx_device *dev,
if (pageneutralcolor && nocm_link->num_in != 1) {
gsicc_mcm_set_link(result);
}
-
- /* Now release any tasks/threads waiting for these contents */
- while (result->num_waiting > 0) {
- gx_semaphore_signal(result->wait);
- result->num_waiting--;
- }
- gx_monitor_leave(pgs->icc_link_cache->lock); /* done with updating, let everyone run */
+ result->valid = true;
+ /* Now release any tasks/threads waiting for these contents by unlocking */
+ gx_monitor_leave(result->lock); /* done with updating, let everyone run */
return result;
}