From 01314608565b2c1cf1a9b73f562791b1c335aaa7 Mon Sep 17 00:00:00 2001 From: dirk Date: Tue, 5 Jul 2016 23:09:45 +0200 Subject: [PATCH] OpenCL will be disabled when the cache directory cannot be determined. --- MagickCore/opencl.c | 130 ++++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 60 deletions(-) diff --git a/MagickCore/opencl.c b/MagickCore/opencl.c index 462320f8a..ac4c56ac7 100644 --- a/MagickCore/opencl.c +++ b/MagickCore/opencl.c @@ -268,81 +268,51 @@ static inline void StopAccelerateTimer(AccelerateTimer *timer) static const char *GetOpenCLCacheDirectory() { - if (cache_directory != (char *) NULL) - return(cache_directory); - - if (cache_directory_lock == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&cache_directory_lock); - LockSemaphoreInfo(cache_directory_lock); if (cache_directory == (char *) NULL) { - char - *home, - path[MagickPathExtent], - *temp; + if (cache_directory_lock == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&cache_directory_lock); + LockSemaphoreInfo(cache_directory_lock); + if (cache_directory == (char *) NULL) + { + char + *home, + path[MagickPathExtent], + *temp; - MagickBooleanType - status; + MagickBooleanType + status; - struct stat - attributes; + struct stat + attributes; - home=GetEnvironmentValue("MAGICK_OPENCL_CACHE_DIR"); - if (home == (char *) NULL) - { - home=GetEnvironmentValue("XDG_CACHE_HOME"); + temp=(char *) NULL; + home=GetEnvironmentValue("MAGICK_OPENCL_CACHE_DIR"); if (home == (char *) NULL) - home=GetEnvironmentValue("LOCALAPPDATA"); - if (home == (char *) NULL) - home=GetEnvironmentValue("APPDATA"); - if (home == (char *) NULL) - home=GetEnvironmentValue("USERPROFILE"); - } - - if (home != (char *) NULL) - { - /* first check if $HOME exists */ - (void) FormatLocaleString(path,MagickPathExtent,"%s",home); - status=GetPathAttributes(path,&attributes); - if (status == MagickFalse) - status=MagickCreateDirectory(path); - - /* first check if $HOME/ImageMagick exists */ - if (status != MagickFalse) { - (void) FormatLocaleString(path,MagickPathExtent, - "%s%sImageMagick",home,DirectorySeparator); - - status=GetPathAttributes(path,&attributes); - if (status == MagickFalse) - status=MagickCreateDirectory(path); + home=GetEnvironmentValue("XDG_CACHE_HOME"); + if (home == (char *) NULL) + home=GetEnvironmentValue("LOCALAPPDATA"); + if (home == (char *) NULL) + home=GetEnvironmentValue("APPDATA"); + if (home == (char *) NULL) + home=GetEnvironmentValue("USERPROFILE"); } - if (status != MagickFalse) - { - temp=(char*)AcquireMagickMemory(strlen(path)+1); - CopyMagickString(temp,path,strlen(path)+1); - } - home=DestroyString(home); - } - else - { - home=GetEnvironmentValue("HOME"); if (home != (char *) NULL) { - /* first check if $HOME/.cache exists */ - (void) FormatLocaleString(path,MagickPathExtent,"%s%s.cache", - home,DirectorySeparator); + /* first check if $HOME exists */ + (void) FormatLocaleString(path,MagickPathExtent,"%s",home); status=GetPathAttributes(path,&attributes); if (status == MagickFalse) status=MagickCreateDirectory(path); - /* first check if $HOME/.cache/ImageMagick exists */ + /* first check if $HOME/ImageMagick exists */ if (status != MagickFalse) { (void) FormatLocaleString(path,MagickPathExtent, - "%s%s.cache%sImageMagick",home,DirectorySeparator, - DirectorySeparator); + "%s%sImageMagick",home,DirectorySeparator); + status=GetPathAttributes(path,&attributes); if (status == MagickFalse) status=MagickCreateDirectory(path); @@ -350,15 +320,50 @@ static const char *GetOpenCLCacheDirectory() if (status != MagickFalse) { - temp=(char*)AcquireMagickMemory(strlen(path)+1); + temp=(char*) AcquireMagickMemory(strlen(path)+1); CopyMagickString(temp,path,strlen(path)+1); } home=DestroyString(home); } + else + { + home=GetEnvironmentValue("HOME"); + if (home != (char *) NULL) + { + /* first check if $HOME/.cache exists */ + (void) FormatLocaleString(path,MagickPathExtent,"%s%s.cache", + home,DirectorySeparator); + status=GetPathAttributes(path,&attributes); + if (status == MagickFalse) + status=MagickCreateDirectory(path); + + /* first check if $HOME/.cache/ImageMagick exists */ + if (status != MagickFalse) + { + (void) FormatLocaleString(path,MagickPathExtent, + "%s%s.cache%sImageMagick",home,DirectorySeparator, + DirectorySeparator); + status=GetPathAttributes(path,&attributes); + if (status == MagickFalse) + status=MagickCreateDirectory(path); + } + + if (status != MagickFalse) + { + temp=(char*) AcquireMagickMemory(strlen(path)+1); + CopyMagickString(temp,path,strlen(path)+1); + } + home=DestroyString(home); + } + } + if (temp == (char *) NULL) + temp=AcquireString("?"); + cache_directory=temp; } - cache_directory=temp; + UnlockSemaphoreInfo(cache_directory_lock); } - UnlockSemaphoreInfo(cache_directory_lock); + if (*cache_directory == '?') + return((const char *) NULL); return(cache_directory); } @@ -1459,6 +1464,8 @@ MagickPrivate void DumpOpenCLProfileData() j; clEnv=GetCurrentOpenCLEnv(); + if (clEnv == (MagickCLEnv) NULL) + return; for (i = 0; i < clEnv->number_devices; i++) if (clEnv->devices[i]->profile_kernels != MagickFalse) @@ -1676,6 +1683,9 @@ MagickPrivate MagickCLEnv GetCurrentOpenCLEnv(void) return(default_CLEnv); } + if (GetOpenCLCacheDirectory() == (char *) NULL) + return((MagickCLEnv) NULL); + if (openCL_lock == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&openCL_lock); -- 2.40.0