From: cristy Date: Tue, 24 Jan 2012 16:39:46 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~6311 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c11dacef705c151ed54ef04628d7ef800086e081;p=imagemagick --- diff --git a/MagickCore/cache-private.h b/MagickCore/cache-private.h index 118a5a5a2..bfceb8ce0 100644 --- a/MagickCore/cache-private.h +++ b/MagickCore/cache-private.h @@ -239,8 +239,9 @@ extern MagickPrivate Quantum *GetAuthenticPixelCacheNexus(Image *,const ssize_t,const ssize_t, const size_t,const size_t,NexusInfo *,ExceptionInfo *), *GetPixelCacheNexusPixels(const Cache,NexusInfo *), - *QueueAuthenticNexus(Image *,const ssize_t,const ssize_t,const size_t, - const size_t,const MagickBooleanType,NexusInfo *,ExceptionInfo *); + *QueueAuthenticPixelCacheNexus(Image *,const ssize_t,const ssize_t, + const size_t,const size_t,const MagickBooleanType,NexusInfo *, + ExceptionInfo *); extern MagickPrivate size_t GetPixelCacheChannels(const Cache); diff --git a/MagickCore/cache-view.c b/MagickCore/cache-view.c index 1a810945e..c2062b651 100644 --- a/MagickCore/cache-view.c +++ b/MagickCore/cache-view.c @@ -850,8 +850,8 @@ MagickExport Quantum *QueueCacheViewAuthenticPixels(CacheView *cache_view, assert(cache_view != (CacheView *) NULL); assert(cache_view->signature == MagickSignature); assert(id < (int) cache_view->number_threads); - pixels=QueueAuthenticNexus(cache_view->image,x,y,columns,rows,MagickFalse, - cache_view->nexus_info[id],exception); + pixels=QueueAuthenticPixelCacheNexus(cache_view->image,x,y,columns,rows, + MagickFalse,cache_view->nexus_info[id],exception); return(pixels); } diff --git a/MagickCore/cache.c b/MagickCore/cache.c index e35c1bde9..c6185d48f 100644 --- a/MagickCore/cache.c +++ b/MagickCore/cache.c @@ -75,6 +75,8 @@ Define declarations. */ #define CacheTick(offset,extent) QuantumTick((MagickOffsetType) offset,extent) +#define IsFileDescriptorLimitExceeded() (GetMagickResource(FileResource) > \ + GetMagickResourceLimit(FileResource) ? MagickTrue : MagickFalse) /* Typedef declarations. @@ -155,9 +157,6 @@ static volatile MagickBooleanType static SemaphoreInfo *cache_semaphore = (SemaphoreInfo *) NULL; - -static SplayTreeInfo - *cache_resources = (SplayTreeInfo *) NULL; /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -206,22 +205,6 @@ MagickPrivate Cache AcquirePixelCache(const size_t number_threads) cache_info->disk_semaphore=AllocateSemaphoreInfo(); cache_info->debug=IsEventLogging(); cache_info->signature=MagickSignature; - if ((cache_resources == (SplayTreeInfo *) NULL) && - (instantiate_cache == MagickFalse)) - { - if (cache_semaphore == (SemaphoreInfo *) NULL) - AcquireSemaphoreInfo(&cache_semaphore); - LockSemaphoreInfo(cache_semaphore); - if ((cache_resources == (SplayTreeInfo *) NULL) && - (instantiate_cache == MagickFalse)) - { - cache_resources=NewSplayTree((int (*)(const void *,const void *)) - NULL,(void *(*)(void *)) NULL,(void *(*)(void *)) NULL); - instantiate_cache=MagickTrue; - } - UnlockSemaphoreInfo(cache_semaphore); - } - (void) AddValueToSplayTree(cache_resources,cache_info,cache_info); return((Cache ) cache_info); } @@ -365,8 +348,6 @@ MagickPrivate void CacheComponentTerminus(void) if (cache_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&cache_semaphore); LockSemaphoreInfo(cache_semaphore); - if (cache_resources != (SplayTreeInfo *) NULL) - cache_resources=DestroySplayTree(cache_resources); instantiate_cache=MagickFalse; UnlockSemaphoreInfo(cache_semaphore); DestroySemaphoreInfo(&cache_semaphore); @@ -569,49 +550,6 @@ static MagickBooleanType ClosePixelCacheOnDisk(CacheInfo *cache_info) return(status == -1 ? MagickFalse : MagickTrue); } -static void LimitPixelCacheDescriptors(void) -{ - register CacheInfo - *p, - *q; - - /* - Limit # of open file descriptors. - */ - if (GetMagickResource(FileResource) < GetMagickResourceLimit(FileResource)) - return; - LockSemaphoreInfo(cache_semaphore); - if (cache_resources == (SplayTreeInfo *) NULL) - { - UnlockSemaphoreInfo(cache_semaphore); - return; - } - ResetSplayTreeIterator(cache_resources); - p=(CacheInfo *) GetNextKeyInSplayTree(cache_resources); - while (p != (CacheInfo *) NULL) - { - if ((p->type == DiskCache) && (p->file != -1)) - break; - p=(CacheInfo *) GetNextKeyInSplayTree(cache_resources); - } - for (q=p; p != (CacheInfo *) NULL; ) - { - if ((p->type == DiskCache) && (p->file != -1) && - (p->timestamp < q->timestamp)) - q=p; - p=(CacheInfo *) GetNextKeyInSplayTree(cache_resources); - } - if (q != (CacheInfo *) NULL) - { - /* - Close least recently used cache. - */ - (void) close(q->file); - q->file=(-1); - } - UnlockSemaphoreInfo(cache_semaphore); -} - static inline MagickSizeType MagickMax(const MagickSizeType x, const MagickSizeType y) { @@ -643,7 +581,6 @@ static MagickBooleanType OpenPixelCacheOnDisk(CacheInfo *cache_info, UnlockSemaphoreInfo(cache_info->disk_semaphore); return(MagickTrue); /* cache already open */ } - LimitPixelCacheDescriptors(); if (*cache_info->cache_filename == '\0') file=AcquireUniqueFileResource(cache_info->cache_filename); else @@ -1428,8 +1365,6 @@ MagickPrivate Cache DestroyPixelCache(Cache cache) return((Cache) NULL); } UnlockSemaphoreInfo(cache_info->semaphore); - if (cache_resources != (SplayTreeInfo *) NULL) - (void) DeleteNodeByValueFromSplayTree(cache_resources,cache_info); if (cache_info->debug != MagickFalse) { char @@ -1687,7 +1622,8 @@ MagickPrivate Quantum *GetAuthenticPixelCacheNexus(Image *image, */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); - q=QueueAuthenticNexus(image,x,y,columns,rows,MagickTrue,nexus_info,exception); + q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickTrue,nexus_info, + exception); if (q == (Quantum *) NULL) return((Quantum *) NULL); cache_info=(CacheInfo *) image->cache; @@ -2119,7 +2055,12 @@ static Cache GetImagePixelCache(Image *image,const MagickBooleanType clone, image->taint=MagickTrue; image->type=UndefinedType; if (ValidatePixelCacheMorphology(image) == MagickFalse) - status=OpenPixelCache(image,IOMode,exception); + { + status=OpenPixelCache(image,IOMode,exception); + cache_info=(CacheInfo *) image->cache; + if (cache_info->type == DiskCache) + (void) ClosePixelCacheOnDisk(cache_info); + } } UnlockSemaphoreInfo(image->semaphore); if (status == MagickFalse) @@ -4379,21 +4320,21 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image, % % % % % % -+ Q u e u e A u t h e n t i c N e x u s % ++ Q u e u e A u t h e n t i c P i x e l C a c h e N e x u s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% QueueAuthenticNexus() allocates an region to store image pixels as defined -% by the region rectangle and returns a pointer to the region. This region is -% subsequently transferred from the pixel cache with +% QueueAuthenticPixelCacheNexus() allocates an region to store image pixels as +% defined by the region rectangle and returns a pointer to the region. This +% region is subsequently transferred from the pixel cache with % SyncAuthenticPixelsCache(). A pointer to the pixels is returned if the % pixels are transferred, otherwise a NULL is returned. % -% The format of the QueueAuthenticNexus() method is: +% The format of the QueueAuthenticPixelCacheNexus() method is: % -% Quantum *QueueAuthenticNexus(Image *image,const ssize_t x, +% Quantum *QueueAuthenticPixelCacheNexus(Image *image,const ssize_t x, % const ssize_t y,const size_t columns,const size_t rows, % const MagickBooleanType clone,NexusInfo *nexus_info, % ExceptionInfo *exception) @@ -4412,8 +4353,8 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image, % o exception: return any errors or warnings in this structure. % */ -MagickPrivate Quantum *QueueAuthenticNexus(Image *image,const ssize_t x, - const ssize_t y,const size_t columns,const size_t rows, +MagickPrivate Quantum *QueueAuthenticPixelCacheNexus(Image *image, + const ssize_t x,const ssize_t y,const size_t columns,const size_t rows, const MagickBooleanType clone,NexusInfo *nexus_info,ExceptionInfo *exception) { CacheInfo @@ -4520,7 +4461,7 @@ static Quantum *QueueAuthenticPixelsCache(Image *image,const ssize_t x, cache_info=(CacheInfo *) image->cache; assert(cache_info->signature == MagickSignature); assert(id < (int) cache_info->number_threads); - q=QueueAuthenticNexus(image,x,y,columns,rows,MagickFalse, + q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickFalse, cache_info->nexus_info[id],exception); return(q); } @@ -4607,7 +4548,7 @@ MagickExport Quantum *QueueAuthenticPixels(Image *image,const ssize_t x, return(q); } assert(id < (int) cache_info->number_threads); - q=QueueAuthenticNexus(image,x,y,columns,rows,MagickFalse, + q=QueueAuthenticPixelCacheNexus(image,x,y,columns,rows,MagickFalse, cache_info->nexus_info[id],exception); return(q); } @@ -4726,6 +4667,8 @@ static MagickBooleanType ReadPixelCacheMetacontent(CacheInfo *cache_info, offset+=cache_info->columns; q+=cache_info->metacontent_extent*nexus_info->region.width; } + if (IsFileDescriptorLimitExceeded() != MagickFalse) + (void) ClosePixelCacheOnDisk(cache_info); if (y < (ssize_t) rows) { ThrowFileException(exception,CacheError,"UnableToReadPixelCache", @@ -4855,6 +4798,8 @@ static MagickBooleanType ReadPixelCachePixels(CacheInfo *cache_info, offset+=cache_info->columns; q+=cache_info->number_channels*nexus_info->region.width; } + if (IsFileDescriptorLimitExceeded() != MagickFalse) + (void) ClosePixelCacheOnDisk(cache_info); if (y < (ssize_t) rows) { ThrowFileException(exception,CacheError,"UnableToReadPixelCache", @@ -5519,6 +5464,8 @@ static MagickBooleanType WritePixelCacheMetacontent(CacheInfo *cache_info, p+=nexus_info->region.width*cache_info->metacontent_extent; offset+=cache_info->columns; } + if (IsFileDescriptorLimitExceeded() != MagickFalse) + (void) ClosePixelCacheOnDisk(cache_info); if (y < (ssize_t) rows) { ThrowFileException(exception,CacheError,"UnableToWritePixelCache", @@ -5649,6 +5596,8 @@ static MagickBooleanType WritePixelCachePixels(CacheInfo *cache_info, p+=nexus_info->region.width*cache_info->number_channels; offset+=cache_info->columns; } + if (IsFileDescriptorLimitExceeded() != MagickFalse) + (void) ClosePixelCacheOnDisk(cache_info); if (y < (ssize_t) rows) { ThrowFileException(exception,CacheError,"UnableToWritePixelCache", diff --git a/MagickCore/methods.h b/MagickCore/methods.h index 855f4f9de..23f34a132 100644 --- a/MagickCore/methods.h +++ b/MagickCore/methods.h @@ -838,7 +838,7 @@ extern "C" { #define QueryColorname PrependMagickMethod(QueryColorname) #define QueryColorname PrependMagickMethod(QueryColorname) #define QueryMagickColor PrependMagickMethod(QueryMagickColor) -#define QueueAuthenticNexus PrependMagickMethod(QueueAuthenticNexus) +#define QueueAuthenticPixelCacheNexus PrependMagickMethod(QueueAuthenticPixelCacheNexus) #define QueueAuthenticPixels PrependMagickMethod(QueueAuthenticPixels) #define QueueCacheViewAuthenticPixels PrependMagickMethod(QueueCacheViewAuthenticPixels) #define RadialBlurImage PrependMagickMethod(RadialBlurImage)