From 1460f26c740619877283a50656e43db099ebfa1c Mon Sep 17 00:00:00 2001 From: cristy Date: Sat, 15 Mar 2014 17:38:05 +0000 Subject: [PATCH] --- MagickCore/coder.c | 30 ++++------------- MagickCore/color.c | 30 ++++------------- MagickCore/configure.c | 30 ++++------------- MagickCore/delegate.c | 30 ++++------------- MagickCore/locale.c | 70 ++++++++++++++++---------------------- MagickCore/log.c | 29 ++++------------ MagickCore/magic.c | 30 ++++------------- MagickCore/magick.c | 65 +++++++++++++++--------------------- MagickCore/mime.c | 30 ++++------------- MagickCore/module.c | 69 +++++++++++++------------------------- MagickCore/policy.c | 30 ++++------------- MagickCore/registry.c | 17 +++------- MagickCore/semaphore.c | 76 +++++++++++++++++++++--------------------- MagickCore/type.c | 32 +++++------------- 14 files changed, 184 insertions(+), 384 deletions(-) diff --git a/MagickCore/coder.c b/MagickCore/coder.c index 7eafc13e1..6736d8105 100644 --- a/MagickCore/coder.c +++ b/MagickCore/coder.c @@ -235,9 +235,6 @@ static SemaphoreInfo static SplayTreeInfo *coder_list = (SplayTreeInfo *) NULL; - -static volatile MagickBooleanType - instantiate_coder = MagickFalse; /* Forward declarations. @@ -295,7 +292,6 @@ MagickPrivate void CoderComponentTerminus(void) LockSemaphoreInfo(coder_semaphore); if (coder_list != (SplayTreeInfo *) NULL) coder_list=DestroySplayTree(coder_list); - instantiate_coder=MagickFalse; UnlockSemaphoreInfo(coder_semaphore); RelinquishSemaphoreInfo(&coder_semaphore); } @@ -329,13 +325,9 @@ MagickExport const CoderInfo *GetCoderInfo(const char *name, ExceptionInfo *exception) { assert(exception != (ExceptionInfo *) NULL); - if ((coder_list == (SplayTreeInfo *) NULL) || - (instantiate_coder == MagickFalse)) + if (coder_list == (SplayTreeInfo *) NULL) if (InitializeCoderList(exception) == MagickFalse) return((const CoderInfo *) NULL); - if ((coder_list == (SplayTreeInfo *) NULL) || - (GetNumberOfNodesInSplayTree(coder_list) == 0)) - return((const CoderInfo *) NULL); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { ResetSplayTreeIterator(coder_list); @@ -539,20 +531,12 @@ MagickExport char **GetCoderList(const char *pattern, */ static MagickBooleanType InitializeCoderList(ExceptionInfo *exception) { - if ((coder_list == (SplayTreeInfo *) NULL) || - (instantiate_coder == MagickFalse)) - { - if (coder_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&coder_semaphore); - LockSemaphoreInfo(coder_semaphore); - if ((coder_list == (SplayTreeInfo *) NULL) || - (instantiate_coder == MagickFalse)) - { - (void) LoadCoderLists(MagickCoderFilename,exception); - instantiate_coder=MagickTrue; - } - UnlockSemaphoreInfo(coder_semaphore); - } + if (coder_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&coder_semaphore); + LockSemaphoreInfo(coder_semaphore); + if (coder_list == (SplayTreeInfo *) NULL) + (void) LoadCoderLists(MagickCoderFilename,exception); + UnlockSemaphoreInfo(coder_semaphore); return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } diff --git a/MagickCore/color.c b/MagickCore/color.c index 0c5f2c6ac..80eb10ac4 100644 --- a/MagickCore/color.c +++ b/MagickCore/color.c @@ -789,9 +789,6 @@ static LinkedListInfo static SemaphoreInfo *color_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_color = MagickFalse; /* Forward declarations. @@ -867,7 +864,6 @@ MagickPrivate void ColorComponentTerminus(void) LockSemaphoreInfo(color_semaphore); if (color_list != (LinkedListInfo *) NULL) color_list=DestroyLinkedList(color_list,DestroyColorElement); - instantiate_color=MagickFalse; UnlockSemaphoreInfo(color_semaphore); RelinquishSemaphoreInfo(&color_semaphore); } @@ -913,13 +909,9 @@ MagickExport const ColorInfo *GetColorCompliance(const char *name, *q; assert(exception != (ExceptionInfo *) NULL); - if ((color_list == (LinkedListInfo *) NULL) || - IfMagickFalse(instantiate_color)) + if (color_list == (LinkedListInfo *) NULL) if (IfMagickFalse(InitializeColorList(exception))) return((const ColorInfo *) NULL); - if ((color_list == (LinkedListInfo *) NULL) || - IfMagickTrue(IsLinkedListEmpty(color_list))) - return((const ColorInfo *) NULL); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) return((const ColorInfo *) GetValueFromLinkedList(color_list,0)); /* @@ -1515,20 +1507,12 @@ MagickExport void GetColorTuple(const PixelInfo *pixel, */ static MagickBooleanType InitializeColorList(ExceptionInfo *exception) { - if ((color_list == (LinkedListInfo *) NULL) || - IfMagickFalse(instantiate_color)) - { - if (color_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&color_semaphore); - LockSemaphoreInfo(color_semaphore); - if ((color_list == (LinkedListInfo *) NULL) || - IfMagickFalse(instantiate_color)) - { - (void) LoadColorLists(ColorFilename,exception); - instantiate_color=MagickTrue; - } - UnlockSemaphoreInfo(color_semaphore); - } + if (color_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&color_semaphore); + LockSemaphoreInfo(color_semaphore); + if (color_list == (LinkedListInfo *) NULL) + (void) LoadColorLists(ColorFilename,exception); + UnlockSemaphoreInfo(color_semaphore); return(color_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } diff --git a/MagickCore/configure.c b/MagickCore/configure.c index 6e9749655..0a74ab529 100644 --- a/MagickCore/configure.c +++ b/MagickCore/configure.c @@ -111,9 +111,6 @@ static LinkedListInfo static SemaphoreInfo *configure_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_configure = MagickFalse; /* Forward declarations. @@ -192,7 +189,6 @@ MagickPrivate void ConfigureComponentTerminus(void) if (configure_list != (LinkedListInfo *) NULL) configure_list=DestroyLinkedList(configure_list,DestroyConfigureElement); configure_list=(LinkedListInfo *) NULL; - instantiate_configure=MagickFalse; UnlockSemaphoreInfo(configure_semaphore); RelinquishSemaphoreInfo(&configure_semaphore); } @@ -269,13 +265,9 @@ MagickExport const ConfigureInfo *GetConfigureInfo(const char *name, *p; assert(exception != (ExceptionInfo *) NULL); - if ((configure_list == (LinkedListInfo *) NULL) || - (instantiate_configure == MagickFalse)) + if (configure_list == (LinkedListInfo *) NULL) if (InitializeConfigureList(exception) == MagickFalse) return((const ConfigureInfo *) NULL); - if ((configure_list == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(configure_list) != MagickFalse)) - return((const ConfigureInfo *) NULL); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) return((const ConfigureInfo *) GetValueFromLinkedList(configure_list,0)); /* @@ -902,20 +894,12 @@ MagickExport const char *GetConfigureValue(const ConfigureInfo *configure_info) */ static MagickBooleanType InitializeConfigureList(ExceptionInfo *exception) { - if ((configure_list == (LinkedListInfo *) NULL) || - (instantiate_configure == MagickFalse)) - { - if (configure_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&configure_semaphore); - LockSemaphoreInfo(configure_semaphore); - if ((configure_list == (LinkedListInfo *) NULL) || - (instantiate_configure == MagickFalse)) - { - (void) LoadConfigureLists(ConfigureFilename,exception); - instantiate_configure=MagickTrue; - } - UnlockSemaphoreInfo(configure_semaphore); - } + if (configure_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&configure_semaphore); + LockSemaphoreInfo(configure_semaphore); + if (configure_list == (LinkedListInfo *) NULL) + (void) LoadConfigureLists(ConfigureFilename,exception); + UnlockSemaphoreInfo(configure_semaphore); return(configure_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } diff --git a/MagickCore/delegate.c b/MagickCore/delegate.c index 890468be8..14067c900 100644 --- a/MagickCore/delegate.c +++ b/MagickCore/delegate.c @@ -133,9 +133,6 @@ static LinkedListInfo static SemaphoreInfo *delegate_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_delegate = MagickFalse; /* Forward declaractions. @@ -212,7 +209,6 @@ MagickPrivate void DelegateComponentTerminus(void) LockSemaphoreInfo(delegate_semaphore); if (delegate_list != (LinkedListInfo *) NULL) delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate); - instantiate_delegate=MagickFalse; UnlockSemaphoreInfo(delegate_semaphore); RelinquishSemaphoreInfo(&delegate_semaphore); } @@ -370,13 +366,9 @@ MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, *p; assert(exception != (ExceptionInfo *) NULL); - if ((delegate_list == (LinkedListInfo *) NULL) || - (IfMagickFalse(instantiate_delegate))) + if (delegate_list == (LinkedListInfo *) NULL) if( IfMagickFalse(InitializeDelegateList(exception)) ) return((const DelegateInfo *) NULL); - if ((delegate_list == (LinkedListInfo *) NULL) || - (IfMagickTrue(IsLinkedListEmpty(delegate_list)))) - return((const DelegateInfo *) NULL); if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0)) return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0)); /* @@ -710,20 +702,12 @@ MagickExport MagickBooleanType GetDelegateThreadSupport( */ static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception) { - if ((delegate_list == (LinkedListInfo *) NULL) || - IfMagickFalse(instantiate_delegate)) - { - if (delegate_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&delegate_semaphore); - LockSemaphoreInfo(delegate_semaphore); - if ((delegate_list == (LinkedListInfo *) NULL) || - IfMagickFalse(instantiate_delegate)) - { - (void) LoadDelegateLists(DelegateFilename,exception); - instantiate_delegate=MagickTrue; - } - UnlockSemaphoreInfo(delegate_semaphore); - } + if (delegate_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&delegate_semaphore); + LockSemaphoreInfo(delegate_semaphore); + if (delegate_list == (LinkedListInfo *) NULL) + (void) LoadDelegateLists(DelegateFilename,exception); + UnlockSemaphoreInfo(delegate_semaphore); return(IsMagickNotNULL(delegate_list)); } diff --git a/MagickCore/locale.c b/MagickCore/locale.c index 0f688b09b..ba70de648 100644 --- a/MagickCore/locale.c +++ b/MagickCore/locale.c @@ -99,9 +99,6 @@ static SplayTreeInfo static volatile locale_t c_locale = (locale_t) NULL; #endif - -static volatile MagickBooleanType - instantiate_locale = MagickFalse; /* Forward declarations. @@ -424,13 +421,9 @@ MagickExport const LocaleInfo *GetLocaleInfo_(const char *tag, ExceptionInfo *exception) { assert(exception != (ExceptionInfo *) NULL); - if ((locale_list == (SplayTreeInfo *) NULL) || - (instantiate_locale == MagickFalse)) + if (locale_list == (SplayTreeInfo *) NULL) if (InitializeLocaleList(exception) == MagickFalse) return((const LocaleInfo *) NULL); - if ((locale_list == (SplayTreeInfo *) NULL) || - (GetNumberOfNodesInSplayTree(locale_list) == 0)) - return((const LocaleInfo *) NULL); if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0)) { ResetSplayTreeIterator(locale_list); @@ -813,41 +806,35 @@ MagickExport const char *GetLocaleValue(const LocaleInfo *locale_info) */ static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception) { - if ((locale_list == (SplayTreeInfo *) NULL) && - (instantiate_locale == MagickFalse)) + if (locale_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&locale_semaphore); + LockSemaphoreInfo(locale_semaphore); + if (locale_list == (SplayTreeInfo *) NULL) { - if (locale_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&locale_semaphore); - LockSemaphoreInfo(locale_semaphore); - if ((locale_list == (SplayTreeInfo *) NULL) || - (instantiate_locale == MagickFalse)) - { - char - *locale; - - register const char - *p; - - locale=(char *) NULL; - p=setlocale(LC_CTYPE,(const char *) NULL); - if (p != (const char *) NULL) - locale=ConstantString(p); - if (locale == (char *) NULL) - locale=GetEnvironmentValue("LC_ALL"); - if (locale == (char *) NULL) - locale=GetEnvironmentValue("LC_MESSAGES"); - if (locale == (char *) NULL) - locale=GetEnvironmentValue("LC_CTYPE"); - if (locale == (char *) NULL) - locale=GetEnvironmentValue("LANG"); - if (locale == (char *) NULL) - locale=ConstantString("C"); - (void) LoadLocaleLists(LocaleFilename,locale,exception); - locale=DestroyString(locale); - instantiate_locale=MagickTrue; - } - UnlockSemaphoreInfo(locale_semaphore); + char + *locale; + + register const char + *p; + + locale=(char *) NULL; + p=setlocale(LC_CTYPE,(const char *) NULL); + if (p != (const char *) NULL) + locale=ConstantString(p); + if (locale == (char *) NULL) + locale=GetEnvironmentValue("LC_ALL"); + if (locale == (char *) NULL) + locale=GetEnvironmentValue("LC_MESSAGES"); + if (locale == (char *) NULL) + locale=GetEnvironmentValue("LC_CTYPE"); + if (locale == (char *) NULL) + locale=GetEnvironmentValue("LANG"); + if (locale == (char *) NULL) + locale=ConstantString("C"); + (void) LoadLocaleLists(LocaleFilename,locale,exception); + locale=DestroyString(locale); } + UnlockSemaphoreInfo(locale_semaphore); return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } @@ -1431,7 +1418,6 @@ MagickPrivate void LocaleComponentTerminus(void) #if defined(MAGICKCORE_HAVE_STRTOD_L) DestroyCLocale(); #endif - instantiate_locale=MagickFalse; UnlockSemaphoreInfo(locale_semaphore); RelinquishSemaphoreInfo(&locale_semaphore); } diff --git a/MagickCore/log.c b/MagickCore/log.c index 022461645..c2f19cd2f 100644 --- a/MagickCore/log.c +++ b/MagickCore/log.c @@ -185,9 +185,6 @@ static LinkedListInfo static SemaphoreInfo *log_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_log = MagickFalse; /* Forward declarations. @@ -274,12 +271,9 @@ static LogInfo *GetLogInfo(const char *name,ExceptionInfo *exception) *p; assert(exception != (ExceptionInfo *) NULL); - if ((log_list == (LinkedListInfo *) NULL) || (instantiate_log == MagickFalse)) + if (log_list == (LinkedListInfo *) NULL) if (InitializeLogList(exception) == MagickFalse) return((LogInfo *) NULL); - if ((log_list == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(log_list) != MagickFalse)) - return((LogInfo *) NULL); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) return((LogInfo *) GetValueFromLinkedList(log_list,0)); /* @@ -535,20 +529,12 @@ MagickExport const char *GetLogName(void) */ static MagickBooleanType InitializeLogList(ExceptionInfo *exception) { - if ((log_list == (LinkedListInfo *) NULL) && - (instantiate_log == MagickFalse)) - { - if (log_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&log_semaphore); - LockSemaphoreInfo(log_semaphore); - if ((log_list == (LinkedListInfo *) NULL) || - (instantiate_log == MagickFalse)) - { - (void) LoadLogLists(LogFilename,exception); - instantiate_log=MagickTrue; - } - UnlockSemaphoreInfo(log_semaphore); - } + if (log_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&log_semaphore); + LockSemaphoreInfo(log_semaphore); + if (log_list == (LinkedListInfo *) NULL) + (void) LoadLogLists(LogFilename,exception); + UnlockSemaphoreInfo(log_semaphore); return(log_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } @@ -765,7 +751,6 @@ MagickPrivate void LogComponentTerminus(void) LockSemaphoreInfo(log_semaphore); if (log_list != (LinkedListInfo *) NULL) log_list=DestroyLinkedList(log_list,DestroyLogElement); - instantiate_log=MagickFalse; UnlockSemaphoreInfo(log_semaphore); RelinquishSemaphoreInfo(&log_semaphore); } diff --git a/MagickCore/magic.c b/MagickCore/magic.c index 948467194..242a4085f 100644 --- a/MagickCore/magic.c +++ b/MagickCore/magic.c @@ -208,9 +208,6 @@ static LinkedListInfo static SemaphoreInfo *magic_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_magic = MagickFalse; /* Forward declarations. @@ -255,13 +252,9 @@ MagickExport const MagicInfo *GetMagicInfo(const unsigned char *magic, *p; assert(exception != (ExceptionInfo *) NULL); - if ((magic_list == (LinkedListInfo *) NULL) || - (instantiate_magic == MagickFalse)) + if (magic_list == (LinkedListInfo *) NULL) if (InitializeMagicList(exception) == MagickFalse) return((const MagicInfo *) NULL); - if ((magic_list == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(magic_list) != MagickFalse)) - return((const MagicInfo *) NULL); if (magic == (const unsigned char *) NULL) return((const MagicInfo *) GetValueFromLinkedList(magic_list,0)); if (length == 0) @@ -529,20 +522,12 @@ MagickExport const char *GetMagicName(const MagicInfo *magic_info) */ static MagickBooleanType InitializeMagicList(ExceptionInfo *exception) { - if ((magic_list == (LinkedListInfo *) NULL) || - (instantiate_magic == MagickFalse)) - { - if (magic_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&magic_semaphore); - LockSemaphoreInfo(magic_semaphore); - if ((magic_list == (LinkedListInfo *) NULL) || - (instantiate_magic == MagickFalse)) - { - (void) LoadMagicLists(MagicFilename,exception); - instantiate_magic=MagickTrue; - } - UnlockSemaphoreInfo(magic_semaphore); - } + if (magic_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&magic_semaphore); + LockSemaphoreInfo(magic_semaphore); + if (magic_list == (LinkedListInfo *) NULL) + (void) LoadMagicLists(MagicFilename,exception); + UnlockSemaphoreInfo(magic_semaphore); return(magic_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } @@ -1075,7 +1060,6 @@ MagickPrivate void MagicComponentTerminus(void) LockSemaphoreInfo(magic_semaphore); if (magic_list != (LinkedListInfo *) NULL) magic_list=DestroyLinkedList(magic_list,DestroyMagicElement); - instantiate_magic=MagickFalse; UnlockSemaphoreInfo(magic_semaphore); RelinquishSemaphoreInfo(&magic_semaphore); } diff --git a/MagickCore/magick.c b/MagickCore/magick.c index 11c79c23d..e59d6e92f 100644 --- a/MagickCore/magick.c +++ b/MagickCore/magick.c @@ -121,7 +121,6 @@ static SplayTreeInfo *magick_list = (SplayTreeInfo *) NULL; static volatile MagickBooleanType - instantiate_magick = MagickFalse, instantiate_magickcore = MagickFalse; /* @@ -413,8 +412,7 @@ MagickExport const MagickInfo *GetMagickInfo(const char *name, *p; assert(exception != (ExceptionInfo *) NULL); - if ((magick_list == (SplayTreeInfo *) NULL) || - (instantiate_magick == MagickFalse)) + if (magick_list == (SplayTreeInfo *) NULL) if (InitializeMagickList(exception) == MagickFalse) return((const MagickInfo *) NULL); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) @@ -840,48 +838,39 @@ static void *DestroyMagickNode(void *magick_info) static MagickBooleanType InitializeMagickList(ExceptionInfo *exception) { (void) exception; - if ((magick_list == (SplayTreeInfo *) NULL) || - (instantiate_magick == MagickFalse)) + if (magick_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&magick_semaphore); + LockSemaphoreInfo(magick_semaphore); + if (magick_list == (SplayTreeInfo *) NULL) { - if (magick_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&magick_semaphore); - LockSemaphoreInfo(magick_semaphore); - if ((magick_list == (SplayTreeInfo *) NULL) || - (instantiate_magick == MagickFalse)) - { - MagickBooleanType - status; + MagickBooleanType + status; - MagickInfo - *magick_info; + MagickInfo + *magick_info; - magick_list=NewSplayTree(CompareSplayTreeString, - (void *(*)(void *)) NULL,DestroyMagickNode); - if (magick_list == (SplayTreeInfo *) NULL) - ThrowFatalException(ResourceLimitFatalError, - "MemoryAllocationFailed"); - magick_info=SetMagickInfo("ephemeral"); - magick_info->stealth=MagickTrue; - status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); - if (status == MagickFalse) - ThrowFatalException(ResourceLimitFatalError, - "MemoryAllocationFailed"); - magick_info=SetMagickInfo("clipmask"); - magick_info->stealth=MagickTrue; - status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); - if (status == MagickFalse) - ThrowFatalException(ResourceLimitFatalError, - "MemoryAllocationFailed"); + magick_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, + DestroyMagickNode); + if (magick_list == (SplayTreeInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + magick_info=SetMagickInfo("ephemeral"); + magick_info->stealth=MagickTrue; + status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); + if (status == MagickFalse) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + magick_info=SetMagickInfo("clipmask"); + magick_info->stealth=MagickTrue; + status=AddValueToSplayTree(magick_list,magick_info->name,magick_info); + if (status == MagickFalse) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); #if defined(MAGICKCORE_MODULES_SUPPORT) - (void) GetModuleInfo((char *) NULL,exception); + (void) GetModuleInfo((char *) NULL,exception); #endif #if !defined(MAGICKCORE_BUILD_MODULES) - RegisterStaticModules(); + RegisterStaticModules(); #endif - instantiate_magick=MagickTrue; - } - UnlockSemaphoreInfo(magick_semaphore); } + UnlockSemaphoreInfo(magick_semaphore); return(magick_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } @@ -1104,7 +1093,6 @@ MagickPrivate void MagickComponentTerminus(void) LockSemaphoreInfo(magick_semaphore); if (magick_list != (SplayTreeInfo *) NULL) magick_list=DestroySplayTree(magick_list); - instantiate_magick=MagickFalse; UnlockSemaphoreInfo(magick_semaphore); RelinquishSemaphoreInfo(&magick_semaphore); } @@ -1175,7 +1163,6 @@ static void MagickSignalHandler(int signal_number) (void) signal(signal_number,SIG_IGN); #endif AsynchronousResourceComponentTerminus(); - instantiate_magick=MagickFalse; (void) SetMagickSignalHandler(signal_number,signal_handlers[signal_number]); #if defined(SIGQUIT) if (signal_number == SIGQUIT) diff --git a/MagickCore/mime.c b/MagickCore/mime.c index d29a46758..778402041 100644 --- a/MagickCore/mime.c +++ b/MagickCore/mime.c @@ -119,9 +119,6 @@ static LinkedListInfo static SemaphoreInfo *mime_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_mime = MagickFalse; /* Forward declarations. @@ -187,13 +184,9 @@ MagickExport const MimeInfo *GetMimeInfo(const char *filename, value; assert(exception != (ExceptionInfo *) NULL); - if ((mime_list == (LinkedListInfo *) NULL) || - (instantiate_mime == MagickFalse)) + if (mime_list == (LinkedListInfo *) NULL) if (InitializeMimeList(exception) == MagickFalse) return((const MimeInfo *) NULL); - if ((mime_list == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(mime_list) != MagickFalse)) - return((const MimeInfo *) NULL); if ((magic == (const unsigned char *) NULL) || (length == 0)) return((const MimeInfo *) GetValueFromLinkedList(mime_list,0)); if (length == 0) @@ -604,20 +597,12 @@ MagickExport const char *GetMimeType(const MimeInfo *mime_info) */ static MagickBooleanType InitializeMimeList(ExceptionInfo *exception) { - if ((mime_list == (LinkedListInfo *) NULL) || - (instantiate_mime == MagickFalse)) - { - if (mime_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&mime_semaphore); - LockSemaphoreInfo(mime_semaphore); - if ((mime_list == (LinkedListInfo *) NULL) || - (instantiate_mime == MagickFalse)) - { - (void) LoadMimeLists(MimeFilename,exception); - instantiate_mime=MagickTrue; - } - UnlockSemaphoreInfo(mime_semaphore); - } + if (mime_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&mime_semaphore); + LockSemaphoreInfo(mime_semaphore); + if (mime_list == (LinkedListInfo *) NULL) + (void) LoadMimeLists(MimeFilename,exception); + UnlockSemaphoreInfo(mime_semaphore); return(mime_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } @@ -1106,7 +1091,6 @@ MagickPrivate void MimeComponentTerminus(void) LockSemaphoreInfo(mime_semaphore); if (mime_list != (LinkedListInfo *) NULL) mime_list=DestroyLinkedList(mime_list,DestroyMimeElement); - instantiate_mime=MagickFalse; UnlockSemaphoreInfo(mime_semaphore); RelinquishSemaphoreInfo(&mime_semaphore); } diff --git a/MagickCore/module.c b/MagickCore/module.c index bbad26033..c4364b21e 100644 --- a/MagickCore/module.c +++ b/MagickCore/module.c @@ -93,9 +93,6 @@ static SemaphoreInfo static SplayTreeInfo *module_list = (SplayTreeInfo *) NULL; - -static volatile MagickBooleanType - instantiate_module = MagickFalse; /* Forward declarations. @@ -184,13 +181,6 @@ MagickExport void DestroyModuleList(void) #if defined(MAGICKCORE_MODULES_SUPPORT) if (module_list != (SplayTreeInfo *) NULL) module_list=DestroySplayTree(module_list); - if (instantiate_module != MagickFalse) - { -#if !defined(MAGICKCORE_JP2_DELEGATE) - (void) lt_dlexit(); /* Jasper has an errant atexit() handler */ -#endif - instantiate_module=MagickFalse; - } #endif UnlockSemaphoreInfo(module_semaphore); } @@ -225,13 +215,9 @@ MagickExport void DestroyModuleList(void) */ MagickExport ModuleInfo *GetModuleInfo(const char *tag,ExceptionInfo *exception) { - if ((module_list == (SplayTreeInfo *) NULL) || - (instantiate_module == MagickFalse)) + if (module_list == (SplayTreeInfo *) NULL) if (InitializeModuleList(exception) == MagickFalse) return((ModuleInfo *) NULL); - if ((module_list == (SplayTreeInfo *) NULL) || - (GetNumberOfNodesInSplayTree(module_list) == 0)) - return((ModuleInfo *) NULL); if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0)) { ModuleInfo @@ -865,39 +851,30 @@ static void *DestroyModuleNode(void *module_info) static MagickBooleanType InitializeModuleList( ExceptionInfo *magick_unused(exception)) { - if ((module_list == (SplayTreeInfo *) NULL) || - (instantiate_module == MagickFalse)) + if (module_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&module_semaphore); + LockSemaphoreInfo(module_semaphore); + if (module_list == (SplayTreeInfo *) NULL) { - if (module_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&module_semaphore); - LockSemaphoreInfo(module_semaphore); - if ((module_list == (SplayTreeInfo *) NULL) || - (instantiate_module == MagickFalse)) - { - MagickBooleanType - status; - - ModuleInfo - *module_info; - - module_list=NewSplayTree(CompareSplayTreeString, - (void *(*)(void *)) NULL,DestroyModuleNode); - if (module_list == (SplayTreeInfo *) NULL) - ThrowFatalException(ResourceLimitFatalError, - "MemoryAllocationFailed"); - module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]"); - module_info->stealth=MagickTrue; - status=AddValueToSplayTree(module_list,module_info->tag,module_info); - if (status == MagickFalse) - ThrowFatalException(ResourceLimitFatalError, - "MemoryAllocationFailed"); - if (lt_dlinit() != 0) - ThrowFatalException(ModuleFatalError, - "UnableToInitializeModuleLoader"); - instantiate_module=MagickTrue; - } - UnlockSemaphoreInfo(module_semaphore); + MagickBooleanType + status; + + ModuleInfo + *module_info; + + module_list=NewSplayTree(CompareSplayTreeString, + (void *(*)(void *)) NULL,DestroyModuleNode); + if (module_list == (SplayTreeInfo *) NULL) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]"); + module_info->stealth=MagickTrue; + status=AddValueToSplayTree(module_list,module_info->tag,module_info); + if (status == MagickFalse) + ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + if (lt_dlinit() != 0) + ThrowFatalException(ModuleFatalError,"UnableToInitializeModuleLoader"); } + UnlockSemaphoreInfo(module_semaphore); return(module_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } diff --git a/MagickCore/policy.c b/MagickCore/policy.c index f4efc4b6e..e05907701 100644 --- a/MagickCore/policy.c +++ b/MagickCore/policy.c @@ -124,9 +124,6 @@ static LinkedListInfo static SemaphoreInfo *policy_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_policy = MagickFalse; /* Forward declarations. @@ -172,13 +169,9 @@ static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception) *q; assert(exception != (ExceptionInfo *) NULL); - if ((policy_list == (LinkedListInfo *) NULL) || - (instantiate_policy == MagickFalse)) + if (policy_list == (LinkedListInfo *) NULL) if (InitializePolicyList(exception) == MagickFalse) return((PolicyInfo *) NULL); - if ((policy_list == (LinkedListInfo *) NULL) || - (IsLinkedListEmpty(policy_list) != MagickFalse)) - return((PolicyInfo *) NULL); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) return((PolicyInfo *) GetValueFromLinkedList(policy_list,0)); /* @@ -425,20 +418,12 @@ MagickExport char *GetPolicyValue(const char *name) */ static MagickBooleanType InitializePolicyList(ExceptionInfo *exception) { - if ((policy_list == (LinkedListInfo *) NULL) || - (instantiate_policy == MagickFalse)) - { - if (policy_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&policy_semaphore); - LockSemaphoreInfo(policy_semaphore); - if ((policy_list == (LinkedListInfo *) NULL) || - (instantiate_policy == MagickFalse)) - { - (void) LoadPolicyLists(PolicyFilename,exception); - instantiate_policy=MagickTrue; - } - UnlockSemaphoreInfo(policy_semaphore); - } + if (policy_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&policy_semaphore); + LockSemaphoreInfo(policy_semaphore); + if (policy_list == (LinkedListInfo *) NULL) + (void) LoadPolicyLists(PolicyFilename,exception); + UnlockSemaphoreInfo(policy_semaphore); return(policy_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); } @@ -1020,7 +1005,6 @@ MagickPrivate void PolicyComponentTerminus(void) LockSemaphoreInfo(policy_semaphore); if (policy_list != (LinkedListInfo *) NULL) policy_list=DestroyLinkedList(policy_list,DestroyPolicyElement); - instantiate_policy=MagickFalse; UnlockSemaphoreInfo(policy_semaphore); RelinquishSemaphoreInfo(&policy_semaphore); } diff --git a/MagickCore/registry.c b/MagickCore/registry.c index d5343c54d..fc228f14d 100644 --- a/MagickCore/registry.c +++ b/MagickCore/registry.c @@ -75,9 +75,6 @@ static SplayTreeInfo static SemaphoreInfo *registry_semaphore = (SemaphoreInfo *) NULL; - -static volatile MagickBooleanType - instantiate_registry = MagickFalse; /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -331,7 +328,6 @@ MagickPrivate void RegistryComponentTerminus(void) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); if (registry != (void *) NULL) registry=DestroySplayTree(registry); - instantiate_registry=MagickFalse; UnlockSemaphoreInfo(registry_semaphore); RelinquishSemaphoreInfo(®istry_semaphore); } @@ -524,19 +520,14 @@ MagickExport MagickBooleanType SetImageRegistry(const RegistryType type, registry_info->type=type; registry_info->value=clone_value; registry_info->signature=MagickSignature; - if ((registry == (SplayTreeInfo *) NULL) && - (instantiate_registry == MagickFalse)) + if (registry == (SplayTreeInfo *) NULL) { if (registry_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(®istry_semaphore); LockSemaphoreInfo(registry_semaphore); - if ((registry == (SplayTreeInfo *) NULL) && - (instantiate_registry == MagickFalse)) - { - registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, - DestroyRegistryNode); - instantiate_registry=MagickTrue; - } + if (registry == (SplayTreeInfo *) NULL) + registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, + DestroyRegistryNode); UnlockSemaphoreInfo(registry_semaphore); } status=AddValueToSplayTree(registry,ConstantString(key),registry_info); diff --git a/MagickCore/semaphore.c b/MagickCore/semaphore.c index f46bf6756..7ed1e0f1c 100644 --- a/MagickCore/semaphore.c +++ b/MagickCore/semaphore.c @@ -75,6 +75,42 @@ struct SemaphoreInfo % % % % % % +% A c t i v a t e S e m a p h o r e I n f o % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% ActivateSemaphoreInfo() activates a semaphore under protection of a mutex +% to ensure only one thread allocates the semaphore. +% +% The format of the ActivateSemaphoreInfo method is: +% +% void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info) +% +% A description of each parameter follows: +% +% o semaphore_info: Specifies a pointer to an SemaphoreInfo structure. +% +*/ +MagickExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info) +{ + assert(semaphore_info != (SemaphoreInfo **) NULL); + if (*semaphore_info == (SemaphoreInfo *) NULL) + { + InitializeMagickMutex(); + LockMagickMutex(); + if (*semaphore_info == (SemaphoreInfo *) NULL) + *semaphore_info=AcquireSemaphoreInfo(); + UnlockMagickMutex(); + } +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % A c q u i r e S e m a p h o r e I n f o % % % % % @@ -158,7 +194,7 @@ MagickExport SemaphoreInfo *AcquireSemaphoreInfo(void) *semaphore_info; /* - Allocate semaphore. + Acquire semaphore. */ semaphore_info=(SemaphoreInfo *) AcquireSemaphoreMemory(1, sizeof(*semaphore_info)); @@ -236,42 +272,6 @@ MagickExport SemaphoreInfo *AcquireSemaphoreInfo(void) % % % % % % -% A c t i v a t e S e m a p h o r e I n f o % -% % -% % -% % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% -% ActivateSemaphoreInfo() activates a semaphore under protection of a mutex -% to ensure only one thread allocates the semaphore. -% -% The format of the ActivateSemaphoreInfo method is: -% -% void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info) -% -% A description of each parameter follows: -% -% o semaphore_info: Specifies a pointer to an SemaphoreInfo structure. -% -*/ -MagickExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info) -{ - assert(semaphore_info != (SemaphoreInfo **) NULL); - if (*semaphore_info == (SemaphoreInfo *) NULL) - { - InitializeMagickMutex(); - LockMagickMutex(); - if (*semaphore_info == (SemaphoreInfo *) NULL) - *semaphore_info=AcquireSemaphoreInfo(); - UnlockMagickMutex(); - } -} - -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% % -% % -% % % L o c k S e m a p h o r e I n f o % % % % % @@ -328,7 +328,7 @@ MagickExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info) % % % % % % -% R e l i n q u i s h S e m a p h o r e I n f o % +% R e l i n q u i s h S e m a p h o r e I n f o % % % % % % % diff --git a/MagickCore/type.c b/MagickCore/type.c index 8b0881236..cffd6738c 100644 --- a/MagickCore/type.c +++ b/MagickCore/type.c @@ -117,9 +117,6 @@ static const char static SemaphoreInfo *type_semaphore = (SemaphoreInfo *) NULL; -static volatile MagickBooleanType - instantiate_type = MagickFalse; - static SplayTreeInfo *type_list = (SplayTreeInfo *) NULL; @@ -159,13 +156,9 @@ MagickExport const TypeInfo *GetTypeInfo(const char *name, ExceptionInfo *exception) { assert(exception != (ExceptionInfo *) NULL); - if ((type_list == (SplayTreeInfo *) NULL) || - (instantiate_type == MagickFalse)) + if (type_list == (SplayTreeInfo *) NULL) if (InitializeTypeList(exception) == MagickFalse) return((const TypeInfo *) NULL); - if ((type_list == (SplayTreeInfo *) NULL) || - (GetNumberOfNodesInSplayTree(type_list) == 0)) - return((const TypeInfo *) NULL); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { ResetSplayTreeIterator(type_list); @@ -782,26 +775,20 @@ MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_list, static MagickBooleanType InitializeTypeList(ExceptionInfo *exception) { - if ((type_list == (SplayTreeInfo *) NULL) || - (instantiate_type == MagickFalse)) + if (type_semaphore == (SemaphoreInfo *) NULL) + ActivateSemaphoreInfo(&type_semaphore); + LockSemaphoreInfo(type_semaphore); + if (type_list == (SplayTreeInfo *) NULL) { - if (type_semaphore == (SemaphoreInfo *) NULL) - ActivateSemaphoreInfo(&type_semaphore); - LockSemaphoreInfo(type_semaphore); - if ((type_list == (SplayTreeInfo *) NULL) || - (instantiate_type == MagickFalse)) - { - (void) LoadTypeLists(MagickTypeFilename,exception); + (void) LoadTypeLists(MagickTypeFilename,exception); #if defined(MAGICKCORE_WINDOWS_SUPPORT) - (void) NTLoadTypeLists(type_list,exception); + (void) NTLoadTypeLists(type_list,exception); #endif #if defined(MAGICKCORE_FONTCONFIG_DELEGATE) - (void) LoadFontConfigFonts(type_list,exception); + (void) LoadFontConfigFonts(type_list,exception); #endif - instantiate_type=MagickTrue; - } - UnlockSemaphoreInfo(type_semaphore); } + UnlockSemaphoreInfo(type_semaphore); return(type_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); } @@ -1390,7 +1377,6 @@ MagickPrivate void TypeComponentTerminus(void) LockSemaphoreInfo(type_semaphore); if (type_list != (SplayTreeInfo *) NULL) type_list=DestroySplayTree(type_list); - instantiate_type=MagickFalse; UnlockSemaphoreInfo(type_semaphore); RelinquishSemaphoreInfo(&type_semaphore); } -- 2.40.0