Define declarations.
*/
#define MagickPathTemplate "XXXXXXXXXXXX"
+#define NumberOfResourceTypes \
+ (sizeof(resource_semaphore)/sizeof(*resource_semaphore))
\f
/*
Typedef declarations.
};
static SemaphoreInfo
- *resource_semaphore = (SemaphoreInfo *) NULL;
+ *resource_semaphore[] = {
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL,
+ (SemaphoreInfo *) NULL
+ };
static SplayTreeInfo
*temporary_resources = (SplayTreeInfo *) NULL;
limit=0;
bi=MagickFalse;
status=MagickFalse;
+ if (resource_semaphore[type] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[type]);
+ LockSemaphoreInfo(resource_semaphore[type]);
switch (type)
{
case AreaResource:
limit=resource_info.area_limit;
break;
}
- case HeightResource:
- {
- bi=MagickTrue;
- resource_info.height=request;
- limit=resource_info.height_limit;
- break;
- }
- case ListLengthResource:
- {
- resource_info.list_length=request;
- limit=resource_info.list_length_limit;
- break;
- }
- case ThreadResource:
- {
- limit=resource_info.thread_limit;
- break;
- }
- case ThrottleResource:
- {
- limit=resource_info.throttle_limit;
- break;
- }
- case WidthResource:
- {
- bi=MagickTrue;
- resource_info.width=request;
- limit=resource_info.width_limit;
- break;
- }
- default:
- break;
- }
- if (limit != 0)
- {
- if ((limit == MagickResourceInfinity) || (size < limit))
- status=MagickTrue;
- if (IsEventLogging() != MagickFalse)
- {
- char
- resource_limit[MagickFormatExtent],
- resource_request[MagickFormatExtent];
-
- (void) FormatMagickSize(size,MagickFalse,(bi != MagickFalse) ?
- "P" : (const char *) NULL,MagickFormatExtent,resource_request);
- (void) FormatMagickSize((MagickSizeType) limit,MagickFalse,
- (bi != MagickFalse) ? "P" : (const char *) NULL,
- MagickFormatExtent,resource_limit);
- (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s",
- CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type),
- resource_request,resource_limit);
- }
- return(status);
- }
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&resource_semaphore);
- LockSemaphoreInfo(resource_semaphore);
- switch (type)
- {
case DiskResource:
{
bi=MagickTrue;
current=resource_info.file;
break;
}
+ case HeightResource:
+ {
+ bi=MagickTrue;
+ resource_info.height=request;
+ limit=resource_info.height_limit;
+ break;
+ }
+ case ListLengthResource:
+ {
+ resource_info.list_length=request;
+ limit=resource_info.list_length_limit;
+ break;
+ }
+ case ThreadResource:
+ {
+ limit=resource_info.thread_limit;
+ break;
+ }
case MapResource:
{
bi=MagickTrue;
current=resource_info.memory;
break;
}
+ case ThrottleResource:
+ {
+ limit=resource_info.throttle_limit;
+ break;
+ }
case TimeResource:
{
limit=resource_info.time_limit;
current=resource_info.time;
break;
}
+ case WidthResource:
+ {
+ bi=MagickTrue;
+ resource_info.width=request;
+ limit=resource_info.width_limit;
+ break;
+ }
default:
{
current=0;
break;
}
}
- UnlockSemaphoreInfo(resource_semaphore);
+ UnlockSemaphoreInfo(resource_semaphore[type]);
+ if ((limit == MagickResourceInfinity) || (size < limit))
+ status=MagickTrue;
if (IsEventLogging() != MagickFalse)
{
char
(void) LogMagickEvent(ResourceEvent,GetMagickModule(),"...");
if (random_info == (RandomInfo *) NULL)
{
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&resource_semaphore);
- LockSemaphoreInfo(resource_semaphore);
+ if (resource_semaphore[FileResource] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
+ LockSemaphoreInfo(resource_semaphore[FileResource]);
if (random_info == (RandomInfo *) NULL)
random_info=AcquireRandomInfo();
- UnlockSemaphoreInfo(resource_semaphore);
+ UnlockSemaphoreInfo(resource_semaphore[FileResource]);
}
file=(-1);
for (i=0; i < (ssize_t) TMP_MAX; i++)
(void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path);
if (file == -1)
return(file);
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&resource_semaphore);
- LockSemaphoreInfo(resource_semaphore);
+ if (resource_semaphore[FileResource] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
+ LockSemaphoreInfo(resource_semaphore[FileResource]);
if (temporary_resources == (SplayTreeInfo *) NULL)
temporary_resources=NewSplayTree(CompareSplayTreeString,
DestroyTemporaryResources,(void *(*)(void *)) NULL);
- UnlockSemaphoreInfo(resource_semaphore);
+ UnlockSemaphoreInfo(resource_semaphore[FileResource]);
(void) AddValueToSplayTree(temporary_resources,ConstantString(path),
(const void *) NULL);
return(file);
resource;
resource=0;
+ if (resource_semaphore[type] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[type]);
+ LockSemaphoreInfo(resource_semaphore[type]);
switch (type)
{
case AreaResource:
resource=(MagickSizeType) resource_info.area;
break;
}
+ case DiskResource:
+ {
+ resource=(MagickSizeType) resource_info.disk;
+ break;
+ }
+ case FileResource:
+ {
+ resource=(MagickSizeType) resource_info.file;
+ break;
+ }
case HeightResource:
{
resource=(MagickSizeType) resource_info.height;
resource=(MagickSizeType) resource_info.list_length;
break;
}
+ case MapResource:
+ {
+ resource=(MagickSizeType) resource_info.map;
+ break;
+ }
+ case MemoryResource:
+ {
+ resource=(MagickSizeType) resource_info.memory;
+ break;
+ }
+ case TimeResource:
+ {
+ resource=(MagickSizeType) resource_info.time;
+ break;
+ }
case ThreadResource:
{
resource=(MagickSizeType) resource_info.thread;
break;
}
default:
- {
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&resource_semaphore);
- LockSemaphoreInfo(resource_semaphore);
- switch (type)
- {
- case DiskResource:
- {
- resource=(MagickSizeType) resource_info.disk;
- break;
- }
- case FileResource:
- {
- resource=(MagickSizeType) resource_info.file;
- break;
- }
- case MapResource:
- {
- resource=(MagickSizeType) resource_info.map;
- break;
- }
- case MemoryResource:
- {
- resource=(MagickSizeType) resource_info.memory;
- break;
- }
- case TimeResource:
- {
- resource=(MagickSizeType) resource_info.time;
- break;
- }
- default:
- break;
- }
- UnlockSemaphoreInfo(resource_semaphore);
break;
- }
}
+ UnlockSemaphoreInfo(resource_semaphore[type]);
return(resource);
}
\f
resource;
resource=0;
+ if (resource_semaphore[type] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[type]);
+ LockSemaphoreInfo(resource_semaphore[type]);
switch (type)
{
case AreaResource:
default:
break;
}
+ UnlockSemaphoreInfo(resource_semaphore[type]);
return(resource);
}
\f
if (file == (const FILE *) NULL)
file=stdout;
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&resource_semaphore);
- LockSemaphoreInfo(resource_semaphore);
+ if (resource_semaphore[FileResource] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
+ LockSemaphoreInfo(resource_semaphore[FileResource]);
(void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P",
MagickFormatExtent,width_limit);
(void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P",
((MagickOffsetType) resource_info.throttle_limit));
(void) FormatLocaleFile(file," Time: %s\n",time_limit);
(void) fflush(file);
- UnlockSemaphoreInfo(resource_semaphore);
+ UnlockSemaphoreInfo(resource_semaphore[FileResource]);
return(MagickTrue);
}
\f
}
bi=MagickFalse;
limit=0;
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&resource_semaphore);
- LockSemaphoreInfo(resource_semaphore);
+ if (resource_semaphore[type] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[type]);
+ LockSemaphoreInfo(resource_semaphore[type]);
switch (type)
{
case DiskResource:
break;
}
}
- UnlockSemaphoreInfo(resource_semaphore);
+ UnlockSemaphoreInfo(resource_semaphore[type]);
if (IsEventLogging() != MagickFalse)
{
char
assert(path != (const char *) NULL);
status=MagickFalse;
(void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path);
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- ActivateSemaphoreInfo(&resource_semaphore);
- LockSemaphoreInfo(resource_semaphore);
+ if (resource_semaphore[FileResource] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
+ LockSemaphoreInfo(resource_semaphore[FileResource]);
if (temporary_resources != (SplayTreeInfo *) NULL)
status=DeleteNodeFromSplayTree(temporary_resources,(const void *) path);
- UnlockSemaphoreInfo(resource_semaphore);
+ UnlockSemaphoreInfo(resource_semaphore[FileResource]);
(void) CopyMagickString(cache_path,path,MagickPathExtent);
AppendImageFormat("cache",cache_path);
if (access_utf8(cache_path,F_OK) == 0)
MagickSizeType
memory;
+ register ssize_t
+ i;
+
ssize_t
files,
pages,
/*
Set Magick resource limits.
*/
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- resource_semaphore=AcquireSemaphoreInfo();
+ for (i=0; i < (ssize_t) NumberOfResourceTypes; i++)
+ if (resource_semaphore[i] == (SemaphoreInfo *) NULL)
+ resource_semaphore[i]=AcquireSemaphoreInfo();
(void) SetMagickResourceLimit(WidthResource,resource_info.width_limit);
limit=GetEnvironmentValue("MAGICK_WIDTH_LIMIT");
if (limit != (char *) NULL)
*/
MagickPrivate void ResourceComponentTerminus(void)
{
- if (resource_semaphore == (SemaphoreInfo *) NULL)
- resource_semaphore=AcquireSemaphoreInfo();
- LockSemaphoreInfo(resource_semaphore);
+ register ssize_t
+ i;
+
+ for (i=0; i < (ssize_t) NumberOfResourceTypes; i++)
+ if (resource_semaphore[i] == (SemaphoreInfo *) NULL)
+ resource_semaphore[i]=AcquireSemaphoreInfo();
+ LockSemaphoreInfo(resource_semaphore[FileResource]);
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);
+ UnlockSemaphoreInfo(resource_semaphore[FileResource]);
+ for (i=0; i < (ssize_t) NumberOfResourceTypes; i++)
+ RelinquishSemaphoreInfo(&resource_semaphore[i]);
}
\f
/*
status=MagickTrue;
value=(char *) NULL;
+ if (resource_semaphore[type] == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&resource_semaphore[type]);
+ LockSemaphoreInfo(resource_semaphore[type]);
switch (type)
{
case AreaResource:
break;
}
}
+ UnlockSemaphoreInfo(resource_semaphore[type]);
if (value != (char *) NULL)
value=DestroyString(value);
return(status);