MagickExport void *ResizeMagickMemory(void *memory,const size_t size) { register void *block; if (memory == (void *) NULL) return(AcquireMagickMemory(size)); #if !defined(UseEmbeddableMagick) block=realloc(memory,size == 0 ? 1UL : size); #else AcquireSemaphoreInfo(&memory_semaphore); block=ResizeBlock(memory,size == 0 ? 1UL : size); if (block == (void *) NULL) { if (ExpandHeap(size == 0 ? 1UL : size) == MagickFalse) { RelinquishSemaphoreInfo(memory_semaphore); memory=RelinquishMagickMemory(memory); ThrowMagickFatalException(ResourceLimitFatalError, "MemoryAllocationFailed",strerror(errno)); } block=ResizeBlock(memory,size == 0 ? 1UL : size); assert(block != (void *) NULL); } RelinquishSemaphoreInfo(memory_semaphore); #endif if (block == (void *) NULL) memory=RelinquishMagickMemory(memory); return(block); }
MagickExport void *ResizeMagickMemory(void *memory,const size_t size) { register void *block; if (memory == (void *) NULL) return(AcquireMagickMemory(size)); #if !defined(MAGICKCORE_EMBEDDABLE_SUPPORT) block=memory_methods.resize_memory_handler(memory,size == 0 ? 1UL : size); if (block == (void *) NULL) memory=RelinquishMagickMemory(memory); #else AcquireSemaphoreInfo(&memory_semaphore); block=ResizeBlock(memory,size == 0 ? 1UL : size); if (block == (void *) NULL) { if (ExpandHeap(size == 0 ? 1UL : size) == MagickFalse) { RelinquishSemaphoreInfo(memory_semaphore); memory=RelinquishMagickMemory(memory); ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); } block=ResizeBlock(memory,size == 0 ? 1UL : size); assert(block != (void *) NULL); } RelinquishSemaphoreInfo(memory_semaphore); memory=RelinquishMagickMemory(memory); #endif return(block); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t C o d e r I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetCoderInfo searches the coder list for the specified name and if found % returns attributes for that coder. % % The format of the GetCoderInfo method is: % % const CoderInfo *GetCoderInfo(const char *name,ExceptionInfo *exception) % % A description of each parameter follows: % % o name: The coder name. % % o exception: Return any errors or warnings in this structure. % % */ MagickExport const CoderInfo *GetCoderInfo(const char *name, ExceptionInfo *exception) { register const CoderInfo *p; assert(exception != (ExceptionInfo *) NULL); if ((coder_list == (SplayTreeInfo *) NULL) || (instantiate_coder == MagickFalse)) 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); return((const CoderInfo *) GetNextValueInSplayTree(coder_list)); } /* Search for requested coder. */ AcquireSemaphoreInfo(&coder_semaphore); ResetSplayTreeIterator(coder_list); p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); while (p != (const CoderInfo *) NULL) { if (LocaleCompare(name,p->magick) == 0) break; p=(const CoderInfo *) GetNextValueInSplayTree(coder_list); } RelinquishSemaphoreInfo(coder_semaphore); return(p); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t M a g i c I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagicInfo() searches the magic list for the specified name and if found % returns attributes for that magic. % % The format of the GetMagicInfo method is: % % const MagicInfo *GetMagicInfo(const unsigned char *magic, % const size_t length,ExceptionInfo *exception) % % A description of each parameter follows: % % o magic: A binary string generally representing the first few characters % of the image file or blob. % % o length: The length of the binary signature. % % o exception: Return any errors or warnings in this structure. % */ MagickExport const MagicInfo *GetMagicInfo(const unsigned char *magic, const size_t length,ExceptionInfo *exception) { register const MagicInfo *p; assert(exception != (ExceptionInfo *) NULL); if ((magic_list == (LinkedListInfo *) NULL) || (instantiate_magic == MagickFalse)) 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) || (length == 0)) return((const MagicInfo *) GetValueFromLinkedList(magic_list,0)); if (length == 0) return((const MagicInfo *) NULL); /* Search for requested magic. */ AcquireSemaphoreInfo(&magic_semaphore); ResetLinkedListIterator(magic_list); p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); while (p != (const MagicInfo *) NULL) { assert(p->offset >= 0); if (((size_t) (p->offset+p->length) <= length) && (memcmp(magic+p->offset,p->magic,p->length) == 0)) break; p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); } RelinquishSemaphoreInfo(magic_semaphore); return((const MagicInfo *) p); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I n i t i a l i z e L o c a l e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InitializeLocaleList() initializes the locale list. % % The format of the InitializeLocaleList method is: % % MagickBooleanType InitializeLocaleList(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: Return any errors or warnings in this structure. % */ static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception) { if ((locale_list == (SplayTreeInfo *) NULL) && (instantiate_locale == MagickFalse)) { AcquireSemaphoreInfo(&locale_semaphore); if ((locale_list == (SplayTreeInfo *) NULL) && (instantiate_locale == MagickFalse)) { char *locale; locale=setlocale(LC_CTYPE,0); if ((locale == (char *) NULL) || (*locale == '\0')) locale=getenv("LC_ALL"); if ((locale == (char *) NULL) || (*locale == '\0')) locale=getenv("LC_MESSAGES"); if ((locale == (char *) NULL) || (*locale == '\0')) locale=getenv("LC_CTYPE"); if ((locale == (char *) NULL) || (*locale == '\0')) locale=getenv("LANG"); if ((locale == (char *) NULL) || (*locale == '\0')) locale="C"; (void) LoadLocaleLists(LocaleFilename,locale,exception); instantiate_locale=MagickTrue; } RelinquishSemaphoreInfo(locale_semaphore); } return((MagickBooleanType) (locale_list != (SplayTreeInfo *) NULL)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t L o c a l e I n f o _ % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetLocaleInfo_() searches the locale list for the specified tag and if % found returns attributes for that element. % % The format of the GetLocaleInfo method is: % % const LocaleInfo *GetLocaleInfo_(const char *tag, % ExceptionInfo *exception) % % A description of each parameter follows: % % o tag: The locale tag. % % o exception: Return any errors or warnings in this structure. % % */ MagickExport const LocaleInfo *GetLocaleInfo_(const char *tag, ExceptionInfo *exception) { register const LocaleInfo *p; assert(exception != (ExceptionInfo *) NULL); if ((locale_list == (SplayTreeInfo *) NULL) || (instantiate_locale == MagickFalse)) 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); return((const LocaleInfo *) GetNextValueInSplayTree(locale_list)); } /* Search for named tag. */ AcquireSemaphoreInfo(&locale_semaphore); ResetSplayTreeIterator(locale_list); p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); while (p != (const LocaleInfo *) NULL) { if (LocaleCompare(tag,p->tag) == 0) break; p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); } RelinquishSemaphoreInfo(locale_semaphore); return(p); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y E x c e p t i o n I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyExceptionInfo() deallocates memory associated with an exception. % % The format of the DestroyExceptionInfo method is: % % ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) % % A description of each parameter follows: % % o exception: the exception info. % */ MagickExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) { MagickBooleanType relinquish; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); if (exception->semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&exception->semaphore); LockSemaphoreInfo(exception->semaphore); exception->severity=UndefinedException; if (exception->relinquish != MagickFalse) { exception->signature=(~MagickCoreSignature); if (exception->exceptions != (void *) NULL) exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *) exception->exceptions,DestroyExceptionElement); } else if (exception->exceptions != (void *) NULL) ClearLinkedList((LinkedListInfo *) exception->exceptions, DestroyExceptionElement); relinquish=exception->relinquish; UnlockSemaphoreInfo(exception->semaphore); if (relinquish != MagickFalse) { RelinquishSemaphoreInfo(&exception->semaphore); exception=(ExceptionInfo *) RelinquishMagickMemory(exception); } return(exception); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i s t M a g i c k R e s o u r c e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ListMagickResourceInfo() lists the resource info to a file. % % The format of the ListMagickResourceInfo method is: % % MagickBooleanType ListMagickResourceInfo(FILE *file, % ExceptionInfo *exception) % % A description of each parameter follows. % % o file: An pointer to a FILE. % % o exception: Return any errors or warnings in this structure. % */ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file, ExceptionInfo *magick_unused(exception)) { char area_limit[MaxTextExtent], disk_limit[MaxTextExtent], map_limit[MaxTextExtent], memory_limit[MaxTextExtent]; if (file == (const FILE *) NULL) file=stdout; AcquireSemaphoreInfo(&resource_semaphore); (void) FormatMagickSize(MegabytesToBytes(resource_info.area_limit), area_limit); (void) FormatMagickSize(GigabytesToBytes(resource_info.disk_limit), disk_limit); (void) FormatMagickSize(MegabytesToBytes(resource_info.map_limit),map_limit); (void) FormatMagickSize(MegabytesToBytes(resource_info.memory_limit), memory_limit); (void) fprintf(file,"File Area Memory Map Disk\n"); (void) fprintf(file,"------------------------------------------------\n"); (void) fprintf(file,"%4lu %9s %9s %9s %9s\n",resource_info.file_limit, area_limit,memory_limit,map_limit,disk_limit); (void) fflush(file); RelinquishSemaphoreInfo(resource_semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y L i n k e d L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyLinkedList() frees the linked-list and all associated resources. % % The format of the DestroyLinkedList method is: % % LinkedListInfo *DestroyLinkedList(LinkedListInfo *list_info, % void *(*relinquish_value)(void *)) % % A description of each parameter follows: % % o list_info: the linked-list info. % % o relinquish_value: the value deallocation method; typically % RelinquishMagickMemory(). % */ MagickExport LinkedListInfo *DestroyLinkedList(LinkedListInfo *list_info, void *(*relinquish_value)(void *)) { ElementInfo *entry; register ElementInfo *next; assert(list_info != (LinkedListInfo *) NULL); assert(list_info->signature == MagickCoreSignature); LockSemaphoreInfo(list_info->semaphore); for (next=list_info->head; next != (ElementInfo *) NULL; ) { if (relinquish_value != (void *(*)(void *)) NULL) next->value=relinquish_value(next->value); entry=next; next=next->next; entry=(ElementInfo *) RelinquishMagickMemory(entry); } list_info->signature=(~MagickCoreSignature); UnlockSemaphoreInfo(list_info->semaphore); RelinquishSemaphoreInfo(&list_info->semaphore); list_info=(LinkedListInfo *) RelinquishMagickMemory(list_info); return(list_info); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y M a g i c k R e s o u r c e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyMagickResources() destroys the resource environment. % % The format of the DestroyMagickResources() method is: % % DestroyMagickResources(void) % */ MagickExport void DestroyMagickResources(void) { AcquireSemaphoreInfo(&resource_semaphore); if (temporary_resources != (SplayTreeInfo *) NULL) temporary_resources=DestroySplayTree(temporary_resources); RelinquishSemaphoreInfo(resource_semaphore); resource_semaphore=DestroySemaphoreInfo(resource_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y L o c a l e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyLocaleList() deallocates memory associated with the locale list. % % The format of the DestroyLocaleList method is: % % DestroyLocaleList(void) % % */ MagickExport void DestroyLocaleList(void) { AcquireSemaphoreInfo(&locale_semaphore); if (locale_list != (SplayTreeInfo *) NULL) locale_list=DestroySplayTree(locale_list); instantiate_locale=MagickFalse; RelinquishSemaphoreInfo(locale_semaphore); locale_semaphore=DestroySemaphoreInfo(locale_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y C o d e r L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyCoderList() deallocates memory associated with the font list. % % The format of the DestroyCoderList method is: % % DestroyCoderList(void) % % */ MagickExport void DestroyCoderList(void) { AcquireSemaphoreInfo(&coder_semaphore); if (coder_list != (SplayTreeInfo *) NULL) coder_list=DestroySplayTree(coder_list); instantiate_coder=MagickFalse; RelinquishSemaphoreInfo(coder_semaphore); coder_semaphore=DestroySemaphoreInfo(coder_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y T y p e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyTypeList() deallocates memory associated with the font list. % % The format of the DestroyTypeList method is: % % DestroyTypeList(void) % */ MagickExport void DestroyTypeList(void) { AcquireSemaphoreInfo(&type_semaphore); if (type_list != (SplayTreeInfo *) NULL) type_list=DestroySplayTree(type_list); instantiate_type=MagickFalse; RelinquishSemaphoreInfo(type_semaphore); type_semaphore=DestroySemaphoreInfo(type_semaphore); }
MagickExport void DestroyMagicList(void) { AcquireSemaphoreInfo(&magic_semaphore); if (magic_list != (LinkedListInfo *) NULL) magic_list=DestroyLinkedList(magic_list,DestroyMagicElement); instantiate_magic=MagickFalse; RelinquishSemaphoreInfo(magic_semaphore); magic_semaphore=DestroySemaphoreInfo(magic_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + T y p e C o m p o n e n t T e r m i n u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TypeComponentTerminus() destroy type component. % % The format of the TypeComponentTerminus method is: % % void TypeComponentTerminus(void) % */ MagickPrivate void TypeComponentTerminus(void) { if (type_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&type_semaphore); LockSemaphoreInfo(type_semaphore); if (type_cache != (SplayTreeInfo *) NULL) type_cache=DestroySplayTree(type_cache); UnlockSemaphoreInfo(type_semaphore); RelinquishSemaphoreInfo(&type_semaphore); }
MagickPrivate void MimeComponentTerminus(void) { if (mime_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&mime_semaphore); LockSemaphoreInfo(mime_semaphore); if (mime_cache != (LinkedListInfo *) NULL) mime_cache=DestroyLinkedList(mime_cache,DestroyMimeElement); UnlockSemaphoreInfo(mime_semaphore); RelinquishSemaphoreInfo(&mime_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagickMemory() returns a pointer to a block of memory at least size % bytes suitably aligned for any use. % % The format of the AcquireMagickMemory method is: % % void *AcquireMagickMemory(const size_t size) % % A description of each parameter follows: % % o size: the size of the memory in bytes to allocate. % */ MagickExport void *AcquireMagickMemory(const size_t size) { register void *memory; #if !defined(MAGICKCORE_EMBEDDABLE_SUPPORT) memory=memory_methods.acquire_memory_handler(size == 0 ? 1UL : size); #else if (free_segments == (DataSegmentInfo *) NULL) { AcquireSemaphoreInfo(&memory_semaphore); if (free_segments == (DataSegmentInfo *) NULL) { register long i; assert(2*sizeof(size_t) > (size_t) (~SizeMask)); (void) ResetMagickMemory(&memory_info,0,sizeof(memory_info)); memory_info.allocation=SegmentSize; memory_info.blocks[MaxBlocks]=(void *) (-1); for (i=0; i < MaxSegments; i++) { if (i != 0) memory_info.segment_pool[i].previous= (&memory_info.segment_pool[i-1]); if (i != (MaxSegments-1)) memory_info.segment_pool[i].next=(&memory_info.segment_pool[i+1]); } free_segments=(&memory_info.segment_pool[0]); } RelinquishSemaphoreInfo(memory_semaphore); } AcquireSemaphoreInfo(&memory_semaphore); memory=AcquireBlock(size == 0 ? 1UL : size); if (memory == (void *) NULL) { if (ExpandHeap(size == 0 ? 1UL : size) != MagickFalse) memory=AcquireBlock(size == 0 ? 1UL : size); } RelinquishSemaphoreInfo(memory_semaphore); #endif return(memory); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + C o d e r C o m p o n e n t T e r m i n u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CoderComponentTerminus() destroys the coder component. % % The format of the CoderComponentTerminus method is: % % CoderComponentTerminus(void) % */ MagickPrivate void CoderComponentTerminus(void) { if (coder_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&coder_semaphore); LockSemaphoreInfo(coder_semaphore); if (coder_cache != (SplayTreeInfo *) NULL) coder_cache=DestroySplayTree(coder_cache); UnlockSemaphoreInfo(coder_semaphore); RelinquishSemaphoreInfo(&coder_semaphore); }
MagickPrivate void PolicyComponentTerminus(void) { if (policy_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&policy_semaphore); LockSemaphoreInfo(policy_semaphore); if (policy_cache != (LinkedListInfo *) NULL) policy_cache=DestroyLinkedList(policy_cache,DestroyPolicyElement); UnlockSemaphoreInfo(policy_semaphore); RelinquishSemaphoreInfo(&policy_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickResource() relinquishes resources of the specified type. % % The format of the RelinquishMagickResource() method is: % % void RelinquishMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: The type of resource. % % o size: The size of the resource. % % */ MagickExport void RelinquishMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MaxTextExtent], resource_limit[MaxTextExtent], resource_request[MaxTextExtent]; FormatSize(size,resource_request); AcquireSemaphoreInfo(&resource_semaphore); switch (type) { case AreaResource: { resource_info.area=size; FormatSize((MagickSizeType) resource_info.area,resource_current); FormatSize(MegabytesToBytes(resource_info.area_limit),resource_limit); break; } case MemoryResource: { resource_info.memory-=size; FormatSize((MagickSizeType) resource_info.memory,resource_current); FormatSize(MegabytesToBytes(resource_info.memory_limit),resource_limit); break; } case MapResource: { resource_info.map-=size; FormatSize((MagickSizeType) resource_info.map,resource_current); FormatSize(MegabytesToBytes(resource_info.map_limit),resource_limit); break; } case DiskResource: { resource_info.disk-=size; FormatSize((MagickSizeType) resource_info.disk,resource_current); FormatSize(GigabytesToBytes(resource_info.disk_limit),resource_limit); break; } case FileResource: { resource_info.file-=size; FormatSize((MagickSizeType) resource_info.file,resource_current); FormatSize((MagickSizeType) resource_info.file_limit,resource_limit); break; } default: break; } RelinquishSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", MagickOptionToMnemonic(MagickResourceOptions,(long) type),resource_request, resource_current,resource_limit); }
WizardExport void ConfigureComponentTerminus(void) { if (configure_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&configure_semaphore); LockSemaphoreInfo(configure_semaphore); if (configure_cache != (LinkedListInfo *) NULL) configure_cache=DestroyLinkedList(configure_cache,DestroyConfigureElement); configure_cache=(LinkedListInfo *) NULL; UnlockSemaphoreInfo(configure_semaphore); RelinquishSemaphoreInfo(&configure_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y Q u a n t u m I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyQuantumInfo() deallocates memory associated with the QuantumInfo % structure. % % The format of the DestroyQuantumInfo method is: % % QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info) % % A description of each parameter follows: % % o quantum_info: the quantum info. % */ MagickExport QuantumInfo *DestroyQuantumInfo(QuantumInfo *quantum_info) { assert(quantum_info != (QuantumInfo *) NULL); assert(quantum_info->signature == MagickCoreSignature); if (quantum_info->pixels != (unsigned char **) NULL) DestroyQuantumPixels(quantum_info); if (quantum_info->semaphore != (SemaphoreInfo *) NULL) RelinquishSemaphoreInfo(&quantum_info->semaphore); quantum_info->signature=(~MagickCoreSignature); quantum_info=(QuantumInfo *) RelinquishMagickMemory(quantum_info); return(quantum_info); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t r y C o m p o n e n t T e r m i n u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegistryComponentTerminus() destroys the registry component. % % The format of the DestroyDefines method is: % % void RegistryComponentTerminus(void) % */ MagickPrivate void RegistryComponentTerminus(void) { if (registry_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(®istry_semaphore); LockSemaphoreInfo(registry_semaphore); if (IsEventLogging() != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); if (registry != (void *) NULL) registry=DestroySplayTree(registry); UnlockSemaphoreInfo(registry_semaphore); RelinquishSemaphoreInfo(®istry_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + R e s o u r c e C o m p o n e n t T e r m i n u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ResourceComponentTerminus() destroys the resource component. % % The format of the ResourceComponentTerminus() method is: % % ResourceComponentTerminus(void) % */ MagickPrivate void ResourceComponentTerminus(void) { if (resource_semaphore == (SemaphoreInfo *) NULL) resource_semaphore=AcquireSemaphoreInfo(); LockSemaphoreInfo(resource_semaphore); if (temporary_resources != (SplayTreeInfo *) NULL) temporary_resources=DestroySplayTree(temporary_resources); if (random_info != (RandomInfo *) NULL) random_info=DestroyRandomInfo(random_info); UnlockSemaphoreInfo(resource_semaphore); RelinquishSemaphoreInfo(&resource_semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I n i t i a l i z e C o d e r L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InitializeCoderList() initializes the coder list. % % The format of the InitializeCoderList method is: % % MagickBooleanType InitializeCoderList(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: Return any errors or warnings in this structure. % */ static MagickBooleanType InitializeCoderList(ExceptionInfo *exception) { if ((coder_list == (SplayTreeInfo *) NULL) && (instantiate_coder == MagickFalse)) { AcquireSemaphoreInfo(&coder_semaphore); if ((coder_list == (SplayTreeInfo *) NULL) && (instantiate_coder == MagickFalse)) { (void) LoadCoderLists(MagickCoderFilename,exception); instantiate_coder=MagickTrue; } RelinquishSemaphoreInfo(coder_semaphore); } return(coder_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I n i t i a l i z e M a g i c L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InitializeMagicList() initializes the magic list. % % The format of the InitializeMagicList method is: % % MagickBooleanType InitializeMagicList(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: Return any errors or warnings in this structure. % */ static MagickBooleanType InitializeMagicList(ExceptionInfo *exception) { if ((magic_list == (LinkedListInfo *) NULL) && (instantiate_magic == MagickFalse)) { AcquireSemaphoreInfo(&magic_semaphore); if ((magic_list == (LinkedListInfo *) NULL) && (instantiate_magic == MagickFalse)) { (void) LoadMagicLists(MagicFilename,exception); instantiate_magic=MagickTrue; } RelinquishSemaphoreInfo(magic_semaphore); } return(magic_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickMemory() frees memory acquired with AcquireMagickMemory() % or AcquireQuantumMemory() for reuse. % % The format of the RelinquishMagickMemory method is: % % void *RelinquishMagickMemory(void *memory) % % A description of each parameter follows: % % o memory: A pointer to a block of memory to free for reuse. % */ MagickExport void *RelinquishMagickMemory(void *memory) { if (memory == (void *) NULL) return((void *) NULL); #if !defined(MAGICKCORE_EMBEDDABLE_SUPPORT) memory_methods.destroy_memory_handler(memory); #else assert((SizeOfBlock(memory) % (4*sizeof(size_t))) == 0); assert((*BlockHeader(NextBlock(memory)) & PreviousBlockBit) != 0); AcquireSemaphoreInfo(&memory_semaphore); if ((*BlockHeader(memory) & PreviousBlockBit) == 0) { void *previous; /* Coalesce with previous adjacent block. */ previous=PreviousBlock(memory); RemoveFreeBlock(previous,AllocationPolicy(SizeOfBlock(previous))); *BlockHeader(previous)=(SizeOfBlock(previous)+SizeOfBlock(memory)) | (*BlockHeader(previous) & ~SizeMask); memory=previous; } if ((*BlockHeader(NextBlock(NextBlock(memory))) & PreviousBlockBit) == 0) { void *next; /* Coalesce with next adjacent block. */ next=NextBlock(memory); RemoveFreeBlock(next,AllocationPolicy(SizeOfBlock(next))); *BlockHeader(memory)=(SizeOfBlock(memory)+SizeOfBlock(next)) | (*BlockHeader(memory) & ~SizeMask); } *BlockFooter(memory,SizeOfBlock(memory))=SizeOfBlock(memory); *BlockHeader(NextBlock(memory))&=(~PreviousBlockBit); InsertFreeBlock(memory,AllocationPolicy(SizeOfBlock(memory))); RelinquishSemaphoreInfo(memory_semaphore); #endif return((void *) NULL); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyMagickMemory() deallocates memory associated with the memory manager. % % The format of the DestroyMagickMemory method is: % % DestroyMagickMemory(void) % */ MagickExport void DestroyMagickMemory(void) { #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT) register long i; AcquireSemaphoreInfo(&memory_semaphore); RelinquishSemaphoreInfo(memory_semaphore); for (i=0; i < (long) memory_info.number_segments; i++) if (memory_info.segments[i]->mapped == MagickFalse) free(memory_info.segments[i]->allocation); else (void) UnmapBlob(memory_info.segments[i]->allocation, memory_info.segments[i]->length); free_segments=(DataSegmentInfo *) NULL; (void) ResetMagickMemory(&memory_info,0,sizeof(memory_info)); memory_semaphore=DestroySemaphoreInfo(memory_semaphore); #endif }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickResource() returns the the specified resource in megabytes. % % The format of the GetMagickResource() method is: % % unsigned long GetMagickResource(const ResourceType type) % % A description of each parameter follows: % % o type: The type of resource. % */ MagickExport unsigned long GetMagickResource(const ResourceType type) { unsigned long resource; resource=0; AcquireSemaphoreInfo(&resource_semaphore); switch (type) { case AreaResource: { resource=BytesToMegabytes(resource_info.area); break; } case MemoryResource: { resource=BytesToMegabytes(resource_info.memory); break; } case MapResource: { resource=BytesToMegabytes(resource_info.map); break; } case DiskResource: { resource=BytesToGigabytes(resource_info.disk); break; } case FileResource: { resource=(unsigned long) resource_info.file; break; } default: break; } RelinquishSemaphoreInfo(resource_semaphore); return(resource); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k R e s o u r c e L i m i t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickResource() returns the the specified resource limit. % % The format of the GetMagickResourceLimit() method is: % % unsigned long GetMagickResourceLimit(const ResourceType type) % % A description of each parameter follows: % % o type: the type of resource. % */ MagickExport MagickSizeType GetMagickResourceLimit(const ResourceType type) { MagickSizeType resource; resource=0; AcquireSemaphoreInfo(&resource_semaphore); switch (type) { case AreaResource: { resource=resource_info.area_limit; break; } case MemoryResource: { resource=resource_info.memory_limit; break; } case MapResource: { resource=resource_info.map_limit; break; } case DiskResource: { resource=resource_info.disk_limit; break; } case FileResource: { resource=resource_info.file_limit; break; } default: break; } RelinquishSemaphoreInfo(resource_semaphore); return(resource); }