]> granicus.if.org Git - imagemagick/commitdiff
Fixed multi-threading issue with Ghostscript under Windows.
authordirk <dirk@git.imagemagick.org>
Wed, 23 Jul 2014 19:21:58 +0000 (19:21 +0000)
committerdirk <dirk@git.imagemagick.org>
Wed, 23 Jul 2014 19:21:58 +0000 (19:21 +0000)
MagickCore/nt-base.c
coders/pdf.c
coders/ps.c

index 4c2bc48849ab6d9d229c604d998c964a5f1d519e..4c3bdf9a3003e65e1fb5f255b98730e4014fe273 100644 (file)
@@ -84,6 +84,9 @@ static GhostInfo
 
 static void
   *ghost_handle = (void *) NULL;
+
+static SemaphoreInfo
+  *ghost_semaphore = (SemaphoreInfo *) NULL;
 \f
 struct
 {
@@ -1359,13 +1362,25 @@ MagickPrivate int NTGhostscriptLoadDLL(void)
   char
     path[MaxTextExtent];
 
+  if (ghost_semaphore == (SemaphoreInfo *) NULL)
+    ActivateSemaphoreInfo(&ghost_semaphore);
+  LockSemaphoreInfo(ghost_semaphore);
   if (ghost_handle != (void *) NULL)
-    return(TRUE);
+    {
+      UnlockSemaphoreInfo(ghost_semaphore);
+      return(TRUE);
+    }
   if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
-    return(FALSE);
+    {
+      UnlockSemaphoreInfo(ghost_semaphore);
+      return(FALSE);
+    }
   ghost_handle=lt_dlopen(path);
   if (ghost_handle == (void *) NULL)
-    return(FALSE);
+    {
+      UnlockSemaphoreInfo(ghost_semaphore);
+      return(FALSE);
+    }
   (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
   ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
     lt_dlsym(ghost_handle,"gsapi_delete_instance"));
@@ -1381,6 +1396,7 @@ MagickPrivate int NTGhostscriptLoadDLL(void)
     MagickDLLCall *)(void *,char *,int),int(MagickDLLCall *)(void *,
     const char *,int),int(MagickDLLCall *)(void *,const char *,int)))
     (lt_dlsym(ghost_handle,"gsapi_set_stdio"));
+  UnlockSemaphoreInfo(ghost_semaphore);
   if ((ghost_info.delete_instance == NULL) || (ghost_info.exit == NULL) ||
       (ghost_info.init_with_args == NULL) || (ghost_info.new_instance == NULL)
       || (ghost_info.run_string == NULL) || (ghost_info.set_stdio == NULL)
@@ -1413,11 +1429,18 @@ MagickPrivate int NTGhostscriptUnLoadDLL(void)
   int
     status;
 
-  if (ghost_handle == (void *) NULL)
-    return(FALSE);
-  status=lt_dlclose(ghost_handle);
-  ghost_handle=(void *) NULL;
-  (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
+  if (ghost_semaphore == (SemaphoreInfo *) NULL)
+    ActivateSemaphoreInfo(&ghost_semaphore);
+  LockSemaphoreInfo(ghost_semaphore);
+  status=FALSE;
+  if (ghost_handle != (void *) NULL)
+    {
+      status=lt_dlclose(ghost_handle);
+      ghost_handle=(void *) NULL;
+      (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
+    }
+  UnlockSemaphoreInfo(ghost_semaphore);
+  RelinquishSemaphoreInfo(&ghost_semaphore);
   return(status);
 }
 \f
index 2f0c237f6ee8f1215c54f0b7534d8ffbb4ea8e04..f3a7a7c0fc9f0bd07a36711312cd12d522b00b8c 100644 (file)
@@ -247,9 +247,6 @@ static MagickBooleanType InvokePDFDelegate(const MagickBooleanType verbose,
       0,&code);
   (ghost_info->exit)(interpreter);
   (ghost_info->delete_instance)(interpreter);
-#if defined(MAGICKCORE_WINDOWS_SUPPORT)
-  NTGhostscriptUnLoadDLL();
-#endif
   for (i=0; i < (ssize_t) argc; i++)
     argv[i]=DestroyString(argv[i]);
   argv=(char **) RelinquishMagickMemory(argv);
index e21e56cb6a4b91dd97ca1e547928bbbcb27499bd..ac43126ad7aa1fcc153ab1ce5df5681983ed2a1e 100644 (file)
@@ -236,9 +236,6 @@ static MagickBooleanType InvokePostscriptDelegate(
       0,&code);
   (ghost_info->exit)(interpreter);
   (ghost_info->delete_instance)(interpreter);
-#if defined(MAGICKCORE_WINDOWS_SUPPORT)
-  NTGhostscriptUnLoadDLL();
-#endif
   for (i=0; i < (ssize_t) argc; i++)
     argv[i]=DestroyString(argv[i]);
   argv=(char **) RelinquishMagickMemory(argv);