% Get/Set MagickCore Resources %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% September 2002 %
% %
% %
-% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#include "MagickCore/log.h"
#include "MagickCore/image.h"
#include "MagickCore/memory_.h"
+#include "MagickCore/nt-base-private.h"
#include "MagickCore/option.h"
#include "MagickCore/policy.h"
#include "MagickCore/random_.h"
disk,
file,
thread,
+ throttle,
time;
MagickSizeType
disk_limit,
file_limit,
thread_limit,
+ throttle_limit,
time_limit;
} ResourceInfo;
\f
static ResourceInfo
resource_info =
{
- MagickULLConstant(0),
- MagickULLConstant(0),
- MagickULLConstant(0),
- MagickULLConstant(0),
- MagickULLConstant(0),
- MagickULLConstant(0),
- MagickULLConstant(0),
- MagickULLConstant(3072)*1024*1024,
- MagickULLConstant(1536)*1024*1024,
- MagickULLConstant(3072)*1024*1024,
- MagickResourceInfinity,
- MagickULLConstant(768),
- MagickULLConstant(1),
- MagickResourceInfinity
+ MagickULLConstant(0), /* initial area */
+ MagickULLConstant(0), /* initial memory */
+ MagickULLConstant(0), /* initial map */
+ MagickULLConstant(0), /* initial disk */
+ MagickULLConstant(0), /* initial file */
+ MagickULLConstant(0), /* initial thread */
+ MagickULLConstant(0), /* initial throttle */
+ MagickULLConstant(0), /* initial time */
+ MagickULLConstant(3072)*1024*1024, /* area limit */
+ MagickULLConstant(1536)*1024*1024, /* memory limit */
+ MagickULLConstant(3072)*1024*1024, /* map limit */
+ MagickResourceInfinity, /* disk limit */
+ MagickULLConstant(768), /* file limit */
+ MagickULLConstant(1), /* thread limit */
+ MagickULLConstant(0), /* throttle limit */
+ MagickResourceInfinity /* time limit */
};
static SemaphoreInfo
status=MagickFalse;
(void) FormatMagickSize(size,MagickFalse,resource_request);
if (resource_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&resource_semaphore);
+ ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
switch (type)
{
resource_info.memory+=size;
limit=resource_info.memory_limit;
status=(resource_info.memory_limit == MagickResourceInfinity) ||
- ((MagickSizeType) resource_info.memory < limit) ?
- MagickTrue : MagickFalse;
+ ((MagickSizeType) resource_info.memory < limit) ? MagickTrue :
+ MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.memory,MagickTrue,
resource_current);
(void) FormatMagickSize(resource_info.memory_limit,MagickTrue,
resource_info.map+=size;
limit=resource_info.map_limit;
status=(resource_info.map_limit == MagickResourceInfinity) ||
- ((MagickSizeType) resource_info.map < limit) ?
- MagickTrue : MagickFalse;
+ ((MagickSizeType) resource_info.map < limit) ? MagickTrue : MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue,
resource_current);
(void) FormatMagickSize(resource_info.map_limit,MagickTrue,
resource_info.disk+=size;
limit=resource_info.disk_limit;
status=(resource_info.disk_limit == MagickResourceInfinity) ||
- ((MagickSizeType) resource_info.disk < limit) ?
- MagickTrue : MagickFalse;
+ ((MagickSizeType) resource_info.disk < limit) ? MagickTrue :
+ MagickFalse;
(void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue,
resource_current);
(void) FormatMagickSize(resource_info.disk_limit,MagickTrue,
MagickFalse,resource_limit);
break;
}
+ case ThrottleResource:
+ {
+ limit=resource_info.throttle_limit;
+ status=(resource_info.throttle_limit == MagickResourceInfinity) ||
+ ((MagickSizeType) resource_info.throttle < limit) ?
+ MagickTrue : MagickFalse;
+ (void) FormatMagickSize((MagickSizeType) resource_info.throttle,
+ MagickFalse,resource_current);
+ (void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit,
+ MagickFalse,resource_limit);
+ break;
+ }
case TimeResource:
{
resource_info.time+=size;
path=(const char *) GetNextKeyInSplayTree(temporary_resources);
while (path != (const char *) NULL)
{
- (void) remove_utf8(path);
+ (void) ShredFile(path);
path=(const char *) GetNextKeyInSplayTree(temporary_resources);
}
}
static void *DestroyTemporaryResources(void *temporary_resource)
{
- (void) remove_utf8((char *) temporary_resource);
+ (void) ShredFile((char *) temporary_resource);
temporary_resource=DestroyString((char *) temporary_resource);
return((void *) NULL);
}
-static MagickBooleanType GetPathTemplate(char *path)
+MagickExport MagickBooleanType GetPathTemplate(char *path)
{
char
*directory,
MagickBooleanType
status;
- register char
- *p;
-
struct stat
attributes;
(void) FormatLocaleString(path,MaxTextExtent,"%smagick-%.20gXXXXXXXXXXXX",
directory,(double) getpid());
else
- (void) FormatLocaleString(path,MaxTextExtent,"%s%smagick-%.20gXXXXXXXXXXXX",
- directory,DirectorySeparator,(double) getpid());
+ (void) FormatLocaleString(path,MaxTextExtent,
+ "%s%smagick-%.20gXXXXXXXXXXXX",directory,DirectorySeparator,
+ (double) getpid());
directory=DestroyString(directory);
- if (*DirectorySeparator != '/')
- for (p=path; *p != '\0'; p++)
+#if defined(MAGICKCORE_WINDOWS_SUPPORT)
+ {
+ register char
+ *p;
+
+ /*
+ Ghostscript does not like backslashes so we need to replace them. The
+ forward slash also works under Windows.
+ */
+ for (p=(path[1] == *DirectorySeparator ? path+2 : path); *p != '\0'; p++)
if (*p == *DirectorySeparator)
*p='/';
+ }
+#endif
return(MagickTrue);
}
*datum;
assert(path != (char *) NULL);
- (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path);
+ (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"...");
if (random_info == (RandomInfo *) NULL)
random_info=AcquireRandomInfo();
file=(-1);
if (file == -1)
return(file);
if (resource_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&resource_semaphore);
+ ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
if (temporary_resources == (SplayTreeInfo *) NULL)
temporary_resources=NewSplayTree(CompareSplayTreeString,
resource=(MagickSizeType) resource_info.thread;
break;
}
+ case ThrottleResource:
+ {
+ resource=(MagickSizeType) resource_info.throttle;
+ break;
+ }
case TimeResource:
{
resource=(MagickSizeType) resource_info.time;
resource=0;
if (resource_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&resource_semaphore);
+ ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
switch (type)
{
resource=resource_info.thread_limit;
break;
}
+ case ThrottleResource:
+ {
+ resource=resource_info.throttle_limit;
+ break;
+ }
case TimeResource:
{
resource=resource_info.time_limit;
if (file == (const FILE *) NULL)
file=stdout;
if (resource_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&resource_semaphore);
+ ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
(void) FormatMagickSize(resource_info.area_limit,MagickFalse,area_limit);
(void) FormatMagickSize(resource_info.memory_limit,MagickTrue,memory_limit);
if (resource_info.time_limit != MagickResourceInfinity)
(void) FormatLocaleString(time_limit,MaxTextExtent,"%.20g",(double)
((MagickOffsetType) resource_info.time_limit));
- (void) FormatLocaleFile(file," File Area Memory Map"
- " Disk Thread Time\n");
+ (void) FormatLocaleFile(file," File Area Memory Map"
+ " Disk Thread Throttle Time\n");
(void) FormatLocaleFile(file,
"--------------------------------------------------------"
- "-----------------------\n");
- (void) FormatLocaleFile(file,"%6g %10s %10s %10s %10s %6g %11s\n",
+ "------------------------\n");
+ (void) FormatLocaleFile(file,"%6g %10s %10s %10s %10s %8g %8g %10s\n",
(double) ((MagickOffsetType) resource_info.file_limit),area_limit,
memory_limit,map_limit,disk_limit,(double) ((MagickOffsetType)
- resource_info.thread_limit),time_limit);
+ resource_info.thread_limit),(double) ((MagickOffsetType)
+ resource_info.throttle_limit),time_limit);
(void) fflush(file);
UnlockSemaphoreInfo(resource_semaphore);
return(MagickTrue);
(void) FormatMagickSize(size,MagickFalse,resource_request);
if (resource_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&resource_semaphore);
+ ActivateSemaphoreInfo(&resource_semaphore);
LockSemaphoreInfo(resource_semaphore);
switch (type)
{
MagickFalse,resource_limit);
break;
}
+ case ThrottleResource:
+ {
+ (void) FormatMagickSize((MagickSizeType) resource_info.throttle,
+ MagickFalse,resource_current);
+ (void) FormatMagickSize((MagickSizeType) resource_info.throttle_limit,
+ MagickFalse,resource_limit);
+ break;
+ }
case TimeResource:
{
resource_info.time-=size;
}
(void) CopyMagickString(cache_path,path,MaxTextExtent);
AppendImageFormat("cache",cache_path);
- (void) remove_utf8(cache_path);
- return(remove_utf8(path) == 0 ? MagickTrue : MagickFalse);
+ (void) ShredFile(cache_path);
+ return(ShredFile(path));
}
\f
/*
/*
Set Magick resource limits.
*/
- AcquireSemaphoreInfo(&resource_semaphore);
+ if (resource_semaphore == (SemaphoreInfo *) NULL)
+ resource_semaphore=AcquireSemaphoreInfo();
pagesize=GetMagickPageSize();
pages=(-1);
#if defined(MAGICKCORE_HAVE_SYSCONF) && defined(_SC_PHYS_PAGES)
memory=PixelCacheThreshold;
#endif
(void) SetMagickResourceLimit(AreaResource,2*memory);
- (void) SetMagickResourceLimit(MemoryResource,memory);
- (void) SetMagickResourceLimit(MapResource,2*memory);
limit=GetEnvironmentValue("MAGICK_AREA_LIMIT");
- if (limit == (char *) NULL)
- limit=GetPolicyValue("area");
if (limit != (char *) NULL)
{
(void) SetMagickResourceLimit(AreaResource,StringToSizeType(limit,100.0));
limit=DestroyString(limit);
}
+ (void) SetMagickResourceLimit(MemoryResource,memory);
limit=GetEnvironmentValue("MAGICK_MEMORY_LIMIT");
- if (limit == (char *) NULL)
- limit=GetPolicyValue("memory");
if (limit != (char *) NULL)
{
(void) SetMagickResourceLimit(MemoryResource,
StringToSizeType(limit,100.0));
limit=DestroyString(limit);
}
+ (void) SetMagickResourceLimit(MapResource,2*memory);
limit=GetEnvironmentValue("MAGICK_MAP_LIMIT");
- if (limit == (char *) NULL)
- limit=GetPolicyValue("map");
if (limit != (char *) NULL)
{
(void) SetMagickResourceLimit(MapResource,StringToSizeType(limit,100.0));
limit=DestroyString(limit);
}
+ (void) SetMagickResourceLimit(DiskResource,MagickResourceInfinity);
limit=GetEnvironmentValue("MAGICK_DISK_LIMIT");
- if (limit == (char *) NULL)
- limit=GetPolicyValue("disk");
if (limit != (char *) NULL)
{
(void) SetMagickResourceLimit(DiskResource,StringToSizeType(limit,100.0));
(void) SetMagickResourceLimit(FileResource,MagickMax((size_t)
(3*files/4),64));
limit=GetEnvironmentValue("MAGICK_FILE_LIMIT");
- if (limit == (char *) NULL)
- limit=GetPolicyValue("file");
if (limit != (char *) NULL)
{
(void) SetMagickResourceLimit(FileResource,StringToSizeType(limit,
}
(void) SetMagickResourceLimit(ThreadResource,GetOpenMPMaximumThreads());
limit=GetEnvironmentValue("MAGICK_THREAD_LIMIT");
- if (limit == (char *) NULL)
- limit=GetPolicyValue("thread");
if (limit != (char *) NULL)
{
(void) SetMagickResourceLimit(ThreadResource,StringToSizeType(limit,
100.0));
limit=DestroyString(limit);
}
+ (void) SetMagickResourceLimit(ThrottleResource,0);
+ limit=GetEnvironmentValue("MAGICK_THROTTLE_LIMIT");
+ if (limit != (char *) NULL)
+ {
+ (void) SetMagickResourceLimit(ThrottleResource,StringToSizeType(limit,
+ 100.0));
+ limit=DestroyString(limit);
+ }
+ (void) SetMagickResourceLimit(TimeResource,MagickResourceInfinity);
limit=GetEnvironmentValue("MAGICK_TIME_LIMIT");
- if (limit == (char *) NULL)
- limit=GetPolicyValue("time");
if (limit != (char *) NULL)
{
(void) SetMagickResourceLimit(TimeResource,StringToSizeType(limit,100.0));
MagickPrivate void ResourceComponentTerminus(void)
{
if (resource_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&resource_semaphore);
+ 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);
- DestroySemaphoreInfo(&resource_semaphore);
+ RelinquishSemaphoreInfo(&resource_semaphore);
}
\f
/*
*value;
if (resource_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&resource_semaphore);
+ resource_semaphore=AcquireSemaphoreInfo();
LockSemaphoreInfo(resource_semaphore);
value=(char *) NULL;
switch (type)
resource_info.thread_limit=GetOpenMPMaximumThreads();
break;
}
+ case ThrottleResource:
+ {
+ resource_info.throttle_limit=limit;
+ value=GetPolicyValue("throttle");
+ if (value != (char *) NULL)
+ resource_info.throttle_limit=MagickMin(limit,StringToSizeType(value,
+ 100.0));
+ if (resource_info.throttle_limit > GetOpenMPMaximumThreads())
+ resource_info.throttle_limit=GetOpenMPMaximumThreads();
+ break;
+ }
case TimeResource:
{
resource_info.time_limit=limit;