From ccfa718b21eb54271859f7aeaeeef995381d7cd5 Mon Sep 17 00:00:00 2001 From: dirk Date: Wed, 23 Jul 2014 19:21:58 +0000 Subject: [PATCH] Fixed multi-threading issue with Ghostscript under Windows. --- MagickCore/nt-base.c | 39 +++++++++++++++++++++++++++++++-------- coders/pdf.c | 3 --- coders/ps.c | 3 --- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/MagickCore/nt-base.c b/MagickCore/nt-base.c index 4c2bc4884..4c3bdf9a3 100644 --- a/MagickCore/nt-base.c +++ b/MagickCore/nt-base.c @@ -84,6 +84,9 @@ static GhostInfo static void *ghost_handle = (void *) NULL; + +static SemaphoreInfo + *ghost_semaphore = (SemaphoreInfo *) NULL; 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); } diff --git a/coders/pdf.c b/coders/pdf.c index 2f0c237f6..f3a7a7c0f 100644 --- a/coders/pdf.c +++ b/coders/pdf.c @@ -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); diff --git a/coders/ps.c b/coders/ps.c index e21e56cb6..ac43126ad 100644 --- a/coders/ps.c +++ b/coders/ps.c @@ -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); -- 2.40.0