speed up logging a bit

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38793 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-07-14 18:51:30 +00:00
parent 78fd39fcd1
commit 136b8c8f49
2 changed files with 32 additions and 22 deletions

View file

@ -87,6 +87,8 @@ extern NSThread *GSCurrentThread();
int _NSLogDescriptor = 2;
static NSRecursiveLock *myLock = nil;
static IMP lockImp = 0;
static IMP unlockImp = 0;
/**
* Returns the lock used to protect the GNUstep NSLogv() implementation.
@ -103,6 +105,8 @@ GSLogLock()
if (myLock == nil)
{
myLock = [NSRecursiveLock new];
lockImp = [myLock methodForSelector: @selector(lock)];
unlockImp = [myLock methodForSelector: @selector(unlock)];
}
[gnustep_global_lock unlock];
}
@ -330,8 +334,8 @@ NSLogv(NSString* format, va_list args)
NSMutableString *prefix;
NSString *message;
NSString *threadName = nil;
NSThread *t = nil;
static int pid = 0;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
if (_NSLog_printf_handler == NULL)
{
@ -349,33 +353,33 @@ NSLogv(NSString* format, va_list args)
if (GSPrivateDefaultsFlag(GSLogThread) == YES)
{
NSThread *t = GSCurrentThread();
threadName = [t name];
/* If no name has been set for the current thread, we log the address
* of the NSThread object instead.
/* If no name has been set for the current thread,
* we log the address of the NSThread object instead.
*/
if ([threadName length] == 0)
{
threadName = [NSString stringWithFormat: @"%p", t];
}
t = GSCurrentThread();
threadName = [t name];
}
prefix = [NSMutableString stringWithCapacity: 1000];
prefix = [[NSMutableString alloc] initWithCapacity: 1000];
#ifdef HAVE_SYSLOG
if (GSPrivateDefaultsFlag(GSLogSyslog) == YES)
{
if (nil != threadName)
{
[prefix appendFormat: @"[thread:%"PRIuPTR",%@] ",
GSPrivateThreadID(), threadName];
}
else
if (nil == t)
{
[prefix appendFormat: @"[thread:%"PRIuPTR"] ",
GSPrivateThreadID()];
}
else if (nil == threadName)
{
[prefix appendFormat: @"[thread:%"PRIuPTR",%p] ",
GSPrivateThreadID(), t];
}
else
{
[prefix appendFormat: @"[thread:%"PRIuPTR",%@] ",
GSPrivateThreadID(), threadName];
}
}
else
#endif
@ -396,11 +400,16 @@ NSLogv(NSString* format, va_list args)
[prefix appendString: cal];
[prefix appendString: @" "];
[prefix appendString: [[NSProcessInfo processInfo] processName]];
if (nil == threadName)
if (nil == t)
{
[prefix appendFormat: @"[%d:%"PRIuPTR"] ",
pid, GSPrivateThreadID()];
}
else if (nil == threadName)
{
[prefix appendFormat: @"[%d:%"PRIuPTR",%p] ",
pid, GSPrivateThreadID(), t];
}
else
{
[prefix appendFormat: @"[%d:%"PRIuPTR",%@] ",
@ -416,17 +425,17 @@ NSLogv(NSString* format, va_list args)
[prefix appendString: @"\n"];
}
if (myLock == nil)
if (nil == myLock)
{
GSLogLock();
}
[myLock lock];
(*lockImp)(myLock, @selector(lock));
_NSLog_printf_handler(prefix);
[myLock unlock];
(*lockImp)(myLock, @selector(unlock));
[arp drain];
[prefix release];
}