From 048a35991bcde121535bd6ff1c56c033029028b4 Mon Sep 17 00:00:00 2001 From: David Ayers Date: Mon, 16 Feb 2004 14:37:46 +0000 Subject: [PATCH] * GSWeb.framework/GSWUtils.h/m (IsStyle,IsNumberStyle, ExceptionRaise, ExceptionRaise0, ValidationExceptionRaise, ValidationExceptionRaise0, ExceptionByAddingUserInfoObjectFrameInfo, ExceptionByAddingUserInfoObjectFrameInfo0, ExceptionByAddingUserInfoFunctionFrameInfo, ExceptionByAddingUserInfoFunctionFrameInfo0, ): Reformat defines. (GSW_LOCK_LIMIT): New define. (ExceptionRaiseFn, ExceptionRaiseFn0, ValidationExceptionRaiseFn, ValidationExceptionRaiseFn0): Reformat declaration. (TmpLock, TmpTryLockBeforeDate, TmpLockBeforeDate, TmpUnlock): Remove. ([NSLock isLocked]): Remove. ([NSLock tmplock]): Ditto. ([NSLock tmplockFromFunction:file:line:]): Ditto. ([NSLock tmptryLock]): Ditto. ([NSLock tmptryLockFromFunction:file:line:]): Ditto. ([NSLock tmptryLockBeforeDate:]): Ditto. ([NSLock tmptryLockBeforeDate:fromFunction:file:line:]): Ditto. ([NSLock tmpunlock]): Ditto. ([NSLock tmpunlockFromFunction:file:line:]): Ditto. ([NSLock description]): Ditto. ([NSRecursiveLock isLocked]): Ditto. ([NSRecursiveLock tmplock]): Ditto. ([NSRecursiveLock tmplockFromFunction:file:line:]): Ditto. ([NSRecursiveLock tmptryLock]): Ditto. ([NSRecursiveLock tmptryLockFromFunction:file:line:]): Ditto. ([NSRecursiveLock tmptryLockBeforeDate:]): Ditto. ([NSRecursiveLock tmptryLockBeforeDate:fromFunction:file:line:]): Ditto. ([NSRecursiveLock tmpunlock]): Ditto. ([NSRecursiveLock tmpunlockFromFunction:file:line:]): Ditto. (NSLockException, MessageForMutexLockError) (LoggedLock, LoggedLockBeforeDate, LoggedTryLock, LoggedTryLockBeforeDate, LoggedUnlock): New macros. (loggedLockBeforeDateFromFunctionInFileInLine, loggedUnlockFromFunctionInFileInLine): New logging lock functions. ([NSThread description]): New Category. (volatileInternalDescription): New static function. (GSW_LOCK_LIMIT): New marco. * GSWeb.framework/GSWApplication.m ([GSWApplication isRequestHandlingLocked]): Test lock instead of relying on obsolete lock categories. ([GSWApplication lockRequestHandling]): Use new locking macros. ([GSWApplication unlockRequestHandling]): Ditto. ([GSWApplication lock]): Ditto. ([GSWApplication unlock]): Ditto. * GSWeb.framework/GSWAssociation.m ([GSWAssociation setClasse:forHandler:]): Ditto ([GSWAssociation addLogHandlerClasse:]): Ditto. ([GSWAssociation removeLogHandlerClasse:]): Ditto. ([GSWAssociation logValue:forSet:]): Ditto. ([GSWAssociation logSynchronizeForValue:inComponent:componentToParent:]): Ditto. * GSWeb.framework/GSWBundle.m ([GSWBundle unlock]): Ditto. ([GSWBundle lock]): Ditto. * GSWeb.framework/GSWDefaultAdaptor.m ([GSWDefaultAdaptor tryLock]): Ditto. ([GSWDefaultAdaptor unlock]): Ditto. * GSWeb.framework/GSWDeployedBundle.m ([GSWDeployedBundle lock]): Ditto. ([GSWDeployedBundle unlock]): Ditto. * GSWeb.framework/GSWResourceManager.m ([GSWResourceManager unlock]): Ditto. ([GSWResourceManager lock]): Ditto. * GSWeb.framework/GSWSessionStore.m ([GSWSessionStore unlock]): Ditto. ([GSWSessionStore tryLock]): Ditto. ([GSWSessionStore lock]): Ditto. * GSWeb.framework/GSWSessionTimeOutManager.m ([GSWSessionTimeOutManager tryLockBeforeTimeIntervalSinceNow:]): Ditto. ([GSWSessionTimeOutManager lockBeforeTimeIntervalSinceNow]): Ditto. ([GSWSessionTimeOutManager unlock]): Ditto. * GSWeb.framework/GSWStaticResourceRequestHandler.m ([GSWStaticResourceRequestHandler handleRequest:]): Ditto. * GSWeb.framework/GSWStatisticsStore.m ([GSWStatisticsStore unlock]): Ditto. ([GSWStatisticsStore lock]): Ditto. * GSWeb.framework/NSObject+IVarAccess+PerformSel.m: ([NSObject getIVarNamed]): Use GSW_LOCK_LIMIT macro. Reformat. ([NSObject setIVarNamed:withValue:]): Ditto. * Makefile.postamble: Remove autom4te.cache on distclean. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@18605 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 90 ++ GSWeb.framework/GSWApplication.m | 24 +- GSWeb.framework/GSWAssociation.m | 24 +- GSWeb.framework/GSWBundle.m | 4 +- GSWeb.framework/GSWDefaultAdaptor.m | 5 +- GSWeb.framework/GSWDeployedBundle.m | 20 +- GSWeb.framework/GSWResourceManager.m | 4 +- GSWeb.framework/GSWSessionStore.m | 6 +- GSWeb.framework/GSWSessionTimeOutManager.m | 7 +- .../GSWStaticResourceRequestHandler.m | 2 +- GSWeb.framework/GSWStatisticsStore.m | 4 +- GSWeb.framework/GSWUtils.h | 177 ++-- GSWeb.framework/GSWUtils.m | 903 +++--------------- .../NSObject+IVarAccess+PerformSel.m | 541 ++++++----- Makefile.postamble | 1 + 15 files changed, 669 insertions(+), 1143 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26a303a..75b26ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,93 @@ +2004-02-16 David Ayers + + * GSWeb.framework/GSWUtils.h/m + (IsStyle,IsNumberStyle, ExceptionRaise, ExceptionRaise0, + ValidationExceptionRaise, ValidationExceptionRaise0, + ExceptionByAddingUserInfoObjectFrameInfo, + ExceptionByAddingUserInfoObjectFrameInfo0, + ExceptionByAddingUserInfoFunctionFrameInfo, + ExceptionByAddingUserInfoFunctionFrameInfo0, ): Reformat defines. + (GSW_LOCK_LIMIT): New define. + (ExceptionRaiseFn, ExceptionRaiseFn0, ValidationExceptionRaiseFn, + ValidationExceptionRaiseFn0): Reformat declaration. + (TmpLock, TmpTryLockBeforeDate, TmpLockBeforeDate, TmpUnlock): + Remove. + ([NSLock isLocked]): Remove. + ([NSLock tmplock]): Ditto. + ([NSLock tmplockFromFunction:file:line:]): Ditto. + ([NSLock tmptryLock]): Ditto. + ([NSLock tmptryLockFromFunction:file:line:]): Ditto. + ([NSLock tmptryLockBeforeDate:]): Ditto. + ([NSLock tmptryLockBeforeDate:fromFunction:file:line:]): Ditto. + ([NSLock tmpunlock]): Ditto. + ([NSLock tmpunlockFromFunction:file:line:]): Ditto. + ([NSLock description]): Ditto. + ([NSRecursiveLock isLocked]): Ditto. + ([NSRecursiveLock tmplock]): Ditto. + ([NSRecursiveLock tmplockFromFunction:file:line:]): Ditto. + ([NSRecursiveLock tmptryLock]): Ditto. + ([NSRecursiveLock tmptryLockFromFunction:file:line:]): Ditto. + ([NSRecursiveLock tmptryLockBeforeDate:]): Ditto. + ([NSRecursiveLock tmptryLockBeforeDate:fromFunction:file:line:]): + Ditto. + ([NSRecursiveLock tmpunlock]): Ditto. + ([NSRecursiveLock tmpunlockFromFunction:file:line:]): Ditto. + (NSLockException, MessageForMutexLockError) + (LoggedLock, LoggedLockBeforeDate, LoggedTryLock, + LoggedTryLockBeforeDate, LoggedUnlock): New macros. + (loggedLockBeforeDateFromFunctionInFileInLine, + loggedUnlockFromFunctionInFileInLine): New logging lock + functions. + ([NSThread description]): New Category. + (volatileInternalDescription): New static function. + (GSW_LOCK_LIMIT): New marco. + * GSWeb.framework/GSWApplication.m + ([GSWApplication isRequestHandlingLocked]): Test lock instead of + relying on obsolete lock categories. + ([GSWApplication lockRequestHandling]): Use new locking macros. + ([GSWApplication unlockRequestHandling]): Ditto. + ([GSWApplication lock]): Ditto. + ([GSWApplication unlock]): Ditto. + * GSWeb.framework/GSWAssociation.m + ([GSWAssociation setClasse:forHandler:]): Ditto + ([GSWAssociation addLogHandlerClasse:]): Ditto. + ([GSWAssociation removeLogHandlerClasse:]): Ditto. + ([GSWAssociation logValue:forSet:]): Ditto. + ([GSWAssociation + logSynchronizeForValue:inComponent:componentToParent:]): Ditto. + * GSWeb.framework/GSWBundle.m + ([GSWBundle unlock]): Ditto. + ([GSWBundle lock]): Ditto. + * GSWeb.framework/GSWDefaultAdaptor.m + ([GSWDefaultAdaptor tryLock]): Ditto. + ([GSWDefaultAdaptor unlock]): Ditto. + * GSWeb.framework/GSWDeployedBundle.m + ([GSWDeployedBundle lock]): Ditto. + ([GSWDeployedBundle unlock]): Ditto. + * GSWeb.framework/GSWResourceManager.m + ([GSWResourceManager unlock]): Ditto. + ([GSWResourceManager lock]): Ditto. + * GSWeb.framework/GSWSessionStore.m + ([GSWSessionStore unlock]): Ditto. + ([GSWSessionStore tryLock]): Ditto. + ([GSWSessionStore lock]): Ditto. + * GSWeb.framework/GSWSessionTimeOutManager.m + ([GSWSessionTimeOutManager tryLockBeforeTimeIntervalSinceNow:]): + Ditto. + ([GSWSessionTimeOutManager lockBeforeTimeIntervalSinceNow]): Ditto. + ([GSWSessionTimeOutManager unlock]): Ditto. + * GSWeb.framework/GSWStaticResourceRequestHandler.m + ([GSWStaticResourceRequestHandler handleRequest:]): Ditto. + * GSWeb.framework/GSWStatisticsStore.m + ([GSWStatisticsStore unlock]): Ditto. + ([GSWStatisticsStore lock]): Ditto. + * GSWeb.framework/NSObject+IVarAccess+PerformSel.m: + ([NSObject getIVarNamed]): Use GSW_LOCK_LIMIT macro. + Reformat. + ([NSObject setIVarNamed:withValue:]): Ditto. + + * Makefile.postamble: Remove autom4te.cache on distclean. + 2004-02-04 Manuel Guesdon * GSWeb.framework/GSWTemplateParserXML.m: fix to avoid html and diff --git a/GSWeb.framework/GSWApplication.m b/GSWeb.framework/GSWApplication.m index b97e400..74a5056 100644 --- a/GSWeb.framework/GSWApplication.m +++ b/GSWeb.framework/GSWApplication.m @@ -936,7 +936,14 @@ int GSWApplicationMain(NSString* applicationClassName, // lockRequestHandling -(BOOL)isRequestHandlingLocked { - return [_globalLock isLocked]; + BOOL lockable = LoggedTryLock(_globalLock); + + if (lockable == YES) + { + LoggedUnlock(_globalLock); + } + + return (lockable ? NO : YES); }; //-------------------------------------------------------------------- @@ -962,8 +969,7 @@ int GSWApplicationMain(NSString* applicationClassName, NS_DURING { NSDebugLockMLog(@"GLOBALLOCK lock ThreadID=%p\n",(void*)objc_thread_id()); - //TODO-NOW TmpLockBeforeDate(globalLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); - [_globalLock lock]; + LoggedLockBeforeDate(_globalLock,GSW_LOCK_LIMIT); NSDebugLockMLog(@"GLOBALLOCK locked ThreadID=%p\n",(void*)objc_thread_id()); #ifndef NDEBUG _globalLockn++; @@ -977,7 +983,7 @@ int GSWApplicationMain(NSString* applicationClassName, NS_HANDLER { localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"globalLock tmplockBeforeDate"); + @"globalLock loggedlockBeforeDate"); LOGException(@"%@ (%@)",localException,[localException reason]); [localException raise]; }; @@ -1008,7 +1014,7 @@ int GSWApplicationMain(NSString* applicationClassName, }; }; NSDebugLockMLog(@"GLOBALLOCK unlock ThreadID=%p\n",(void*)objc_thread_id()); - TmpUnlock(_globalLock); + LoggedUnlock(_globalLock); NSDebugLockMLog(@"GLOBALLOCK unlocked ThreadID=%p\n",(void*)objc_thread_id()); #ifndef NDEBUG _globalLockn--; @@ -1027,7 +1033,7 @@ int GSWApplicationMain(NSString* applicationClassName, (void*)_globalLock_thread_id, (void*)objc_thread_id()); localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"globalLock tmpunlock"); + @"globalLock loggedunlock"); LOGException(@"%@ (%@)",localException,[localException reason]); [localException raise]; }; @@ -1058,7 +1064,7 @@ int GSWApplicationMain(NSString* applicationClassName, NS_DURING { /* printf("SELFLOCK lock ThreadID=%p\n",(void*)objc_thread_id()); - TmpLockBeforeDate(selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(selfLock,GSW_LOCK_LIMIT); printf("SELFLOCK locked ThreadID=%p\n",(void*)objc_thread_id()); #ifndef NDEBUG selfLockn++; @@ -1108,7 +1114,7 @@ selfLockn, NS_DURING { NSDebugLockMLog(@"SELFLOCK unlock ThreadID=%p\n",(void*)objc_thread_id()); - // TmpUnlock(selfLock); + // LoggedUnlock(selfLock); [_selfLock unlock];//NEW NSDebugLockMLog(@"SELFLOCK unlocked ThreadID=%p\n",(void*)objc_thread_id()); #ifndef NDEBUG @@ -1129,7 +1135,7 @@ selfLockn, (void*)_selfLock_thread_id, (void*)objc_thread_id()); localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"selfLock tmpunlock"); + @"selfLock loggedunlock"); LOGException(@"%@ (%@)",localException,[localException reason]); [localException raise]; }; diff --git a/GSWeb.framework/GSWAssociation.m b/GSWeb.framework/GSWAssociation.m index ecbde4f..c2eae4d 100644 --- a/GSWeb.framework/GSWAssociation.m +++ b/GSWeb.framework/GSWAssociation.m @@ -379,7 +379,7 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; LOGClassFnStart(); NSDebugMLLog(@"associations",@"class=%@",class); NSDebugMLLog(@"associations",@"handler=%@",handler); - TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(associationsLock,GSW_LOCK_LIMIT); if (!associationsHandlerClasses) { if (class) @@ -390,7 +390,7 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; forKey:handler]; else if (associationsHandlerClasses) [associationsHandlerClasses removeObjectForKey:handler]; - TmpUnlock(associationsLock); + LoggedUnlock(associationsLock); LOGClassFnStop(); }; @@ -399,7 +399,7 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; { LOGClassFnStart(); NSDebugMLLog(@"associations",@"class=%@",class); - TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(associationsLock,GSW_LOCK_LIMIT); if (!associationsLogsHandlerClasses) { if (class) @@ -407,7 +407,7 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; }; if (class) [associationsLogsHandlerClasses addObject:class]; - TmpUnlock(associationsLock); + LoggedUnlock(associationsLock); LOGClassFnStop(); }; @@ -416,13 +416,13 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; { LOGClassFnStart(); NSDebugMLLog(@"associations",@"class=%@",class); - TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(associationsLock,GSW_LOCK_LIMIT); if (associationsHandlerClasses) { if (class) [associationsLogsHandlerClasses removeObject:class]; }; - TmpUnlock(associationsLock); + LoggedUnlock(associationsLock); LOGClassFnStop(); }; @@ -486,7 +486,7 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; { if (associationsLogsHandlerClasses) { - TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(associationsLock,GSW_LOCK_LIMIT); NS_DURING { int i=0; @@ -513,11 +513,11 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; NS_HANDLER { LOGException(@"%@ (%@)",localException,[localException reason]); - TmpUnlock(associationsLock); + LoggedUnlock(associationsLock); [localException raise]; } NS_ENDHANDLER; - TmpUnlock(associationsLock); + LoggedUnlock(associationsLock); }; }; }; @@ -543,7 +543,7 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; { if (associationsHandlerClasses) { - TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(associationsLock,GSW_LOCK_LIMIT); NS_DURING { int i=0; @@ -565,11 +565,11 @@ static NSMutableArray* associationsLogsHandlerClasses=nil; NS_HANDLER { LOGException(@"%@ (%@)",localException,[localException reason]); - TmpUnlock(associationsLock); + LoggedUnlock(associationsLock); [localException raise]; } NS_ENDHANDLER; - TmpUnlock(associationsLock); + LoggedUnlock(associationsLock); }; }; diff --git a/GSWeb.framework/GSWBundle.m b/GSWeb.framework/GSWBundle.m index 54b96aa..9d3b739 100644 --- a/GSWeb.framework/GSWBundle.m +++ b/GSWeb.framework/GSWBundle.m @@ -197,7 +197,7 @@ objectForReference:(NSString*)keyPath { LOGObjectFnStart(); NSDebugMLLog(@"bundles",@"selfLockn=%d",_selfLockn); - TmpUnlock(_selfLock); + LoggedUnlock(_selfLock); #ifndef NDEBUG _selfLockn--; #endif @@ -210,7 +210,7 @@ objectForReference:(NSString*)keyPath { LOGObjectFnStart(); NSDebugMLLog(@"bundles",@"selfLockn=%d",_selfLockn); - TmpLockBeforeDate(_selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(_selfLock,GSW_LOCK_LIMIT); #ifndef NDEBUG _selfLockn++; #endif diff --git a/GSWeb.framework/GSWDefaultAdaptor.m b/GSWeb.framework/GSWDefaultAdaptor.m index 4661348..d1cca66 100644 --- a/GSWeb.framework/GSWDefaultAdaptor.m +++ b/GSWeb.framework/GSWDefaultAdaptor.m @@ -716,7 +716,8 @@ int allow_severity = LOG_INFO; LOGObjectFnStart(); NSDebugLockMLog(@"self=%p ThreadID=%p TRYLOCK\n", self,(void*)objc_thread_id()); - locked=[_selfLock tmptryLockBeforeDate:[NSDate dateWithTimeIntervalSinceNow:90]]; + locked=LoggedTryLockBeforeDate(_selfLock, + [NSDate dateWithTimeIntervalSinceNow:90]); NSDebugLockMLog(@"self=%p ThreadID=%p TRYLOCK LOCKED ?\n", self,(void*)objc_thread_id()); LOGObjectFnStop(); @@ -730,7 +731,7 @@ int allow_severity = LOG_INFO; LOGObjectFnStart(); NSDebugLockMLog(@"self=%p ThreadID=%p UNLOCK\n", self,(void*)objc_thread_id()); - [_selfLock tmpunlock]; + LoggedUnlock(_selfLock); NSDebugLockMLog(@"self=%p ThreadID=%p UNLOCK UNLOCKED ?\n", self,(void*)objc_thread_id()); LOGObjectFnStop(); diff --git a/GSWeb.framework/GSWDeployedBundle.m b/GSWeb.framework/GSWDeployedBundle.m index 831a768..fb85667 100644 --- a/GSWeb.framework/GSWDeployedBundle.m +++ b/GSWeb.framework/GSWDeployedBundle.m @@ -643,11 +643,13 @@ if it was not cached **/ -(void)lock { LOGObjectFnStart(); - NSDebugMLLog(@"bundles",@"selfLock=%p selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", - (void*)_selfLock, - _selfLockn, - (void*)_selfLock_thread_id, - (void*)objc_thread_id()); + NSDebugMLLog(@"bundles", + @"selfLock=%p selfLockn=%d selfLock_thread_id=%p " + @"objc_thread_id()=%p", + (void*)_selfLock, + _selfLockn, + (void*)_selfLock_thread_id, + (void*)objc_thread_id()); if (_selfLockn>0) { if (_selfLock_thread_id!=objc_thread_id()) @@ -655,12 +657,14 @@ if it was not cached **/ NSDebugMLog0(@"PROBLEM: owner!=thread id"); }; }; - TmpLockBeforeDate(_selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(_selfLock,GSW_LOCK_LIMIT); #ifndef NDEBUG _selfLockn++; _selfLock_thread_id=objc_thread_id(); #endif - NSDebugMLLog(@"bundles",@"selfLock=%p selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + NSDebugMLLog(@"bundles", + @"selfLock=%p selfLockn=%d selfLock_thread_id=%p " + @"objc_thread_id()=%p", _selfLock, _selfLockn, (void*)_selfLock_thread_id, @@ -685,7 +689,7 @@ if it was not cached **/ NSDebugMLog0(@"PROBLEM: owner!=thread id"); }; }; - TmpUnlock(_selfLock); + LoggedUnlock(_selfLock); #ifndef NDEBUG _selfLockn--; if (_selfLockn==0) diff --git a/GSWeb.framework/GSWResourceManager.m b/GSWeb.framework/GSWResourceManager.m index 4f308d1..9dd807a 100644 --- a/GSWeb.framework/GSWResourceManager.m +++ b/GSWeb.framework/GSWResourceManager.m @@ -442,7 +442,7 @@ NSString* localNotFoundMarker=@"NOTFOUND"; { LOGObjectFnStart(); NSDebugMLLog(@"resmanager",@"_selfLockn=%d",_selfLockn); - TmpUnlock(_selfLock); + LoggedUnlock(_selfLock); #ifndef NDEBUG _selfLockn--; #endif @@ -455,7 +455,7 @@ NSString* localNotFoundMarker=@"NOTFOUND"; { LOGObjectFnStart(); NSDebugMLLog(@"resmanager",@"_selfLockn=%d",_selfLockn); - TmpLockBeforeDate(_selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(_selfLock,GSW_LOCK_LIMIT); #ifndef NDEBUG _selfLockn++; #endif diff --git a/GSWeb.framework/GSWSessionStore.m b/GSWeb.framework/GSWSessionStore.m index 2fddfc2..c6a2d0b 100644 --- a/GSWeb.framework/GSWSessionStore.m +++ b/GSWeb.framework/GSWSessionStore.m @@ -318,7 +318,7 @@ RCS_ID("$Id$") { LOGObjectFnStart(); NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - TmpUnlock(_lock); + LoggedUnlock(_lock); #ifndef NDEBUG _lockn--; #endif @@ -332,7 +332,7 @@ RCS_ID("$Id$") BOOL locked=NO; LOGObjectFnStart(); NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - locked=TmpTryLockBeforeDate(_lock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + locked=LoggedTryLockBeforeDate(_lock,GSW_LOCK_LIMIT); #ifndef NDEBUG if (locked) _lockn++; @@ -347,7 +347,7 @@ RCS_ID("$Id$") { LOGObjectFnStart(); NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - TmpLockBeforeDate(_lock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(_lock,GSW_LOCK_LIMIT); #ifndef NDEBUG _lockn++; #endif diff --git a/GSWeb.framework/GSWSessionTimeOutManager.m b/GSWeb.framework/GSWSessionTimeOutManager.m index 7c038a5..5af95ad 100644 --- a/GSWeb.framework/GSWSessionTimeOutManager.m +++ b/GSWeb.framework/GSWSessionTimeOutManager.m @@ -520,7 +520,8 @@ RCS_ID("$Id$") LOGObjectFnStart(); NSDebugMLLog(@"sessions",@"selfLockn=%d lock before %f s (%@)", _selfLockn,ti,[NSDate dateWithTimeIntervalSinceNow:ti]); - locked=TmpTryLockBeforeDate(_selfLock,[NSDate dateWithTimeIntervalSinceNow:ti]); + locked=LoggedTryLockBeforeDate(_selfLock, + [NSDate dateWithTimeIntervalSinceNow:ti]); #ifndef NDEBUG if (locked) _selfLockn++; @@ -536,7 +537,7 @@ RCS_ID("$Id$") LOGObjectFnStart(); NSDebugMLLog(@"sessions",@"selfLockn=%d lock before %f s (%@)", _selfLockn,ti,[NSDate dateWithTimeIntervalSinceNow:ti]); - TmpLockBeforeDate(_selfLock,[NSDate dateWithTimeIntervalSinceNow:ti]); + LoggedLockBeforeDate(_selfLock,[NSDate dateWithTimeIntervalSinceNow:ti]); #ifndef NDEBUG _selfLockn++; #endif @@ -557,7 +558,7 @@ RCS_ID("$Id$") { LOGObjectFnStart(); NSDebugMLLog(@"sessions",@"selfLockn=%d",_selfLockn); - TmpUnlock(_selfLock); + LoggedUnlock(_selfLock); #ifndef NDEBUG _selfLockn--; #endif diff --git a/GSWeb.framework/GSWStaticResourceRequestHandler.m b/GSWeb.framework/GSWStaticResourceRequestHandler.m index a1ce531..4ad8c80 100644 --- a/GSWeb.framework/GSWStaticResourceRequestHandler.m +++ b/GSWeb.framework/GSWStaticResourceRequestHandler.m @@ -71,7 +71,7 @@ RCS_ID("$Id$") NS_HANDLER { localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"globalLock tmplockBeforeDate"); + @"globalLock loggedlockBeforeDate"); LOGException(@"%@ (%@)",localException,[localException reason]); [localException raise]; } diff --git a/GSWeb.framework/GSWStatisticsStore.m b/GSWeb.framework/GSWStatisticsStore.m index 19808f4..ea16b4e 100644 --- a/GSWeb.framework/GSWStatisticsStore.m +++ b/GSWeb.framework/GSWStatisticsStore.m @@ -83,7 +83,7 @@ RCS_ID("$Id$") { LOGObjectFnStart(); NSDebugMLog(@"selfLockn=%d",_selfLockn); - TmpUnlock(_selfLock); + LoggedUnlock(_selfLock); #ifndef NDEBUG _selfLockn--; #endif @@ -96,7 +96,7 @@ RCS_ID("$Id$") { LOGObjectFnStart(); NSDebugMLog(@"selfLockn=%d",_selfLockn); - TmpLockBeforeDate(_selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + LoggedLockBeforeDate(_selfLock, GSW_LOCK_LIMIT); #ifndef NDEBUG _selfLockn++; #endif diff --git a/GSWeb.framework/GSWUtils.h b/GSWeb.framework/GSWUtils.h index 16104ec..d5dbc0f 100644 --- a/GSWeb.framework/GSWUtils.h +++ b/GSWeb.framework/GSWUtils.h @@ -42,8 +42,10 @@ #define min(a,b) ((a) < (b) ? (a) : (b)) #endif -#define IsStyle(__value,__style) ((((__value)&(__style))==(__style)) ? YES : NO) -#define IsNumberStyle(__value,__style) (((([__value unsignedIntValue])&(__style))==(__style)) ? YES : NO) +#define IsStyle(__value,__style) \ + ((((__value)&(__style))==(__style)) ? YES : NO) +#define IsNumberStyle(__value,__style) \ + (((([__value unsignedIntValue])&(__style))==(__style)) ? YES : NO) #define VOID_RCSID \ static void VoidUseRCSId() { rcsId[0]=0; }; @@ -60,45 +62,51 @@ typedef unsigned int UINT32; #define UINTs_DEFINED #endif +#define GSW_LOCK_LIMIT [NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S] + BOOL ClassIsKindOfClass(Class classA,Class classB); void ExceptionRaiseFn(const char *func, - const char *file, - int line, - NSString* name_, - NSString* format_, - ...); + const char *file, + int line, + NSString* name_, + NSString* format_, + ...); void ExceptionRaiseFn0(const char *func, - const char *file, - int line, - NSString* name_, - NSString* format_); + const char *file, + int line, + NSString* name_, + NSString* format_); void ValidationExceptionRaiseFn(const char *func, - const char *file, - int line, - NSString* name_, - NSString* message_, - NSString* format_, - ...); + const char *file, + int line, + NSString* name_, + NSString* message_, + NSString* format_, + ...); void ValidationExceptionRaiseFn0(const char *func, - const char *file, - int line, - NSString* name_, - NSString* message_, - NSString* format_); + const char *file, + int line, + NSString* name_, + NSString* message_, + NSString* format_); -#define ExceptionRaise(name_, format_, args...) \ - { ExceptionRaiseFn(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,format_, ## args); } +#define ExceptionRaise(name_, format_, args...) \ + { ExceptionRaiseFn(__PRETTY_FUNCTION__, __FILE__, __LINE__, \ + name_,format_, ## args); } -#define ExceptionRaise0(name_, format_) \ - { ExceptionRaiseFn0(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,format_); } +#define ExceptionRaise0(name_, format_) \ + { ExceptionRaiseFn0(__PRETTY_FUNCTION__, __FILE__, __LINE__, \ + name_,format_); } -#define ValidationExceptionRaise(name_,message_, format_, args...) \ - { ValidationExceptionRaiseFn(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,message_,format_, ## args); } +#define ValidationExceptionRaise(name_,message_, format_, args...) \ + { ValidationExceptionRaiseFn(__PRETTY_FUNCTION__, __FILE__, __LINE__,\ + name_,message_,format_, ## args); } -#define ValidationExceptionRaise0(name_,message_, format_) \ - { ValidationExceptionRaiseFn0(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,message_,format_); } +#define ValidationExceptionRaise0(name_,message_, format_) \ + { ValidationExceptionRaiseFn0(__PRETTY_FUNCTION__, __FILE__, __LINE__,\ + name_,message_,format_); } extern BOOL boolValueFor(id id_); extern BOOL boolValueWithDefaultFor(id id_,BOOL defaultValue); @@ -186,17 +194,21 @@ extern NSString* GSWGetDefaultDocRoot(); @end -#define ExceptionByAddingUserInfoObjectFrameInfo(_exception,format_, args...) \ -[(_exception) exceptionByAddingUserInfoFrameInfoObject:self sel:_cmd file:__FILE__ line:__LINE__ format:format_, ## args] +#define ExceptionByAddingUserInfoObjectFrameInfo(_exception,format_, args...) \ +[(_exception) exceptionByAddingUserInfoFrameInfoObject:self sel:_cmd \ + file:__FILE__ line:__LINE__ format:format_, ## args] -#define ExceptionByAddingUserInfoObjectFrameInfo0(_exception,format_) \ -[(_exception) exceptionByAddingUserInfoFrameInfoObject:self sel:_cmd file:__FILE__ line:__LINE__ format:format_] +#define ExceptionByAddingUserInfoObjectFrameInfo0(_exception,format_) \ +[(_exception) exceptionByAddingUserInfoFrameInfoObject:self sel:_cmd \ + file:__FILE__ line:__LINE__ format:format_] -#define ExceptionByAddingUserInfoFunctionFrameInfo(format_, args...) \ -[(_exception) exceptionByAddingUserInfoFrameInfoFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__ format:format_, ## args] +#define ExceptionByAddingUserInfoFunctionFrameInfo(format_, args...) \ +[(_exception) exceptionByAddingUserInfoFrameInfoFunction:__PRETTY_FUNCTION__ \ + file:__FILE__ line:__LINE__ format:format_, ## args] -#define ExceptionByAddingUserInfoFunctionFrameInfo0(format_) \ -[(_exception) exceptionByAddingUserInfoFrameInfoFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__ format:format_] +#define ExceptionByAddingUserInfoFunctionFrameInfo0(format_) \ +[(_exception) exceptionByAddingUserInfoFrameInfoFunction:__PRETTY_FUNCTION__ \ + file:__FILE__ line:__LINE__ format:format_] //==================================================================== @interface NSException (NSExceptionUserInfoAdd) @@ -291,70 +303,35 @@ extern NSString* GSWGetDefaultDocRoot(); @end //==================================================================== -#define TmpLock(_lock_) [(_lock_) tmplockFromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] -#define TmpTryLockBeforeDate(_lock_,_limit_) [(_lock_) tmptryLockBeforeDate:(_limit_) fromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] -#define TmpLockBeforeDate(_lock_,_limit_) [(_lock_) tmplockBeforeDate:(_limit_) fromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] -#define TmpUnlock(_lock_) [(_lock_) tmpunlockFromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] +#define LoggedLock(__lock) \ + (loggedLockBeforeDateFromFunctionInFileInLine((__lock), NO, nil, \ + __FILE__, __PRETTY_FUNCTION__, __LINE__)) +#define LoggedLockBeforeDate(__lock,__limit) \ + (loggedLockBeforeDateFromFunctionInFileInLine((__lock), NO, (__limit), \ + __FILE__, __PRETTY_FUNCTION__, __LINE__)) +#define LoggedTryLock(__lock) \ + (loggedLockBeforeDateFromFunctionInFileInLine((__lock), YES, nil, \ + __FILE__, __PRETTY_FUNCTION__, __LINE__)) +#define LoggedTryLockBeforeDate(__lock,__limit) \ + (loggedLockBeforeDateFromFunctionInFileInLine((__lock), YES, (__limit), \ + __FILE__, __PRETTY_FUNCTION__, __LINE__)) +#define LoggedUnlock(__lock) \ + (loggedUnlockFromFunctionInFileInLine(__lock, \ + __FILE__, __PRETTY_FUNCTION__, __LINE__)) -//==================================================================== -@interface NSLock (NSLockBD) --(BOOL)isLocked; --(BOOL)tmplock; --(BOOL)tmplockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; +extern BOOL +loggedLockBeforeDateFromFunctionInFileInLine(id self, + BOOL try, + NSDate *limit, + const char *file, + const char *function, + long line); +extern void +loggedUnlockFromFunctionInFileInLine(id self, + const char *file, + const char *function, + long line); --(BOOL)tmptryLock; --(BOOL)tmptryLockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; - --(BOOL)tmptryLockBeforeDate:(NSDate*)limit; --(BOOL)tmptryLockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line; - --(BOOL)tmplockBeforeDate:(NSDate*)limit; --(BOOL)tmplockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line; - --(void)tmpunlock; --(void)tmpunlockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; -@end - -//==================================================================== -@interface NSRecursiveLock (NSLockBD) --(BOOL)isLocked; --(BOOL)tmplock; --(BOOL)tmplockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; - --(BOOL)tmptryLock; --(BOOL)tmptryLockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; - --(BOOL)tmptryLockBeforeDate:(NSDate*)limit; --(BOOL)tmptryLockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line; --(BOOL)tmplockBeforeDate:(NSDate*)limit; --(BOOL)tmplockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line; --(void)tmpunlock; --(void)tmpunlockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; -@end //==================================================================== @interface NSArray (NSPerformSelectorWith2Objects) diff --git a/GSWeb.framework/GSWUtils.m b/GSWeb.framework/GSWUtils.m index 05db2ac..8758d31 100644 --- a/GSWeb.framework/GSWUtils.m +++ b/GSWeb.framework/GSWUtils.m @@ -37,6 +37,9 @@ RCS_ID("$Id$") #include #include #include +#ifdef GNUSTEP +#include +#endif #include "stacktrace.h" #include "attach.h" //-------------------------------------------------------------------- @@ -867,769 +870,175 @@ void ValidationExceptionRaiseFn0(const char *func, @end -extern struct PTHREAD_HANDLE* nub_get_active_thread(void); - -NSString *NSLockException = @"NSLockException"; - -NSString* MessageForMutexLockError(int errorNo) -{ - NSDebugFLog(@"errorNo=%d",errorNo); - switch(errorNo) - { - case EINVAL: - return @"EINVAL the mutex has not been properly initialized."; - break; - case EDEADLK: - return @"EDEADLK the mutex is already locked by the calling thread"; - break; - case EBUSY: - return @"the mutex could not be acquired or destroyed because it was currently locked."; - break; - case EPERM: - return @"EPERM the calling thread does not own the mutex"; - break; - default: - return [NSString stringWithFormat:@"Unknown %d",errorNo]; - break; - }; -}; //==================================================================== -@implementation NSLock (NSLockBD) --(NSString*)description +#ifdef GNUSTEP +@implementation NSThread (Debugging) +- (NSString *)description { - return [NSString stringWithFormat:@"<%s %p - ", - object_get_class_name(self), - (void*)self]; -}; - -//-------------------------------------------------------------------- --(BOOL)isLocked -{ - BOOL isLocked=YES; - //TODO -#ifdef NeXT_Foundation_LIBRARY - if ([self tmptryLock]) + /* This guards us from associating the wrong objc_thread_id() + when other threads invoke description on us. */ + if (self == [NSThread currentThread]) { - isLocked = NO; - [self tmpunlock]; + return [NSString stringWithFormat: @"<%s: %p (%p)>", + GSClassNameFromObject(self), + self, objc_thread_id()]; } -#else - if (!_mutex->owner) - isLocked=NO; - else - { - NSDebugMLog(@"Locked by _mutex->owner=%p _mutex->depth=%d (this thread=%p)", - (void*)_mutex->owner,(int)_mutex->depth, - (void*)objc_thread_id()); - }; -/* - if ([self tmptryLock]) - { - isLocked=NO; - [self tmpunlock]; - } - else - { - NSDebugMLog(@"Locked by _mutex->owner=%p _mutex->depth=%d (this thread=%p)", - (void*)_mutex->owner,(int)_mutex->depth, - (void*)objc_thread_id()); - }; -*/ -#endif - return isLocked; -}; - -//-------------------------------------------------------------------- --(BOOL)tmplock -{ - return [self tmplockFromFunction:NULL - file:NULL - line:-1]; -}; - - -//-------------------------------------------------------------------- --(BOOL)tmplockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ -//TODO -#ifdef NeXT_Foundation_LIBRARY - return [self tryLock]; -#else - BOOL locked=NO; - int result=0; -// LOGObjectFnStart(); - NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p", - self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner) - { - result=objc_mutex_trylock(_mutex); - // NSDebugMLLog(@"low",@"result=%d",result); - if (result != 0 && result!=1) - locked=NO; - else - locked=YES; - }; -// NSDebugMLLog(@"low",@"locked=%d",(int)locked); - if (locked) - { - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - } - else - { - LOGException(@"NSLockException lock: failed to lock mutex. Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"lock: failed to lock mutex. Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - }; -// LOGObjectFnStop(); - return locked; -#endif -}; - -//-------------------------------------------------------------------- --(BOOL)tmptryLock -{ - return [self tmptryLockFromFunction:NULL - file:NULL - line:-1]; -}; - -//-------------------------------------------------------------------- --(BOOL)tmptryLockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ -//TODO -#ifdef NeXT_Foundation_LIBRARY - return [self tryLock]; -#else - BOOL locked=NO; - int result=0; -// LOGObjectFnStart(); -// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner) - { - result=objc_mutex_trylock(_mutex); - // NSDebugMLLog(@"low",@"result=%d",result); - if (result != 0 && result!=1) - locked=NO; - else - locked=YES; - // LOGObjectFnStop(); - }; - return locked; -#endif -}; - -//-------------------------------------------------------------------- --(BOOL)tmptryLockBeforeDate:(NSDate*)limit -{ - return [self tmptryLockBeforeDate:limit - fromFunction:NULL - file:NULL - line:-1]; -}; - -//-------------------------------------------------------------------- --(BOOL)tmptryLockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ - //TODO -#ifdef NeXT_Foundation_LIBRARY - return [self lockBeforeDate:limit]; -#else - BOOL locked=NO; - int result=0; - int tryCount=0; -// LOGObjectFnStart(); - NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p", - self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner) - { - result=objc_mutex_trylock(_mutex); - // NSDebugMLLog(@"low",@"result=%d",result); - if (result != 0 && result!=1) - locked=NO; - else - locked=YES; - }; - // NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit); - while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) - { - tryCount++; - //NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); - NSTimeIntervalSleep(0.010); - //NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner) - { - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result != 0 && result!=1) - { - if (tryCount%10==0) - NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p", - 10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id()); - locked=NO; - } - else - locked=YES; - } - else - { - if (tryCount%10==0) - NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p", - 10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id()); - locked=NO; - } - }; - // NSDebugMLLog(@"low",@"locked=%d",(int)locked); - if (locked) - { - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - } - else - { - NSDebugMLog(@"NSLock tmptryLockBeforeDate lock: failed to lock mutex before %@. Called from %s in %s %d", - limit, - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - }; - // LOGObjectFnStop(); - return locked; -#endif -}; - -//-------------------------------------------------------------------- --(BOOL)tmplockBeforeDate:(NSDate*)limit -{ - return [self tmplockBeforeDate:limit - fromFunction:NULL - file:NULL - line:-1]; -}; - -//-------------------------------------------------------------------- --(BOOL)tmplockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ - //TODO -#ifdef NeXT_Foundation_LIBRARY - return [self lockBeforeDate:limit]; -#else - BOOL locked=NO; - int result=0; - int tryCount=0; -// LOGObjectFnStart(); - NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p", - self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner) - { - result=objc_mutex_trylock(_mutex); - // NSDebugMLLog(@"low",@"result=%d",result); - if (result != 0 && result!=1) - locked=NO; - else - locked=YES; - }; - -// NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit); - while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) - { - tryCount++; - //NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); - NSTimeIntervalSleep(0.010); - //NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner) - { - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result != 0 && result!=1) - { - if (tryCount%10==0) - NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p", - 10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id()); - locked=NO; - } - else - locked=YES; - } - else - { - if (tryCount%10==0) - NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p", - 10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id()); - locked=NO; - }; - }; - // NSDebugMLLog(@"low",@"locked=%d",(int)locked); - if (locked) - { - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - } - else - { - LOGException(@"NSLockException lock: failed to lock mutex before date %@. Called from %s in %s %d", - limit, - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"lock: failed to lock mutex before date %@. Called from %s in %s %d", - limit, - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - }; -// LOGObjectFnStop(); - return locked; -#endif -}; - -//-------------------------------------------------------------------- --(void)tmpunlock -{ - [self tmpunlockFromFunction:NULL - file:NULL - line:-1]; -}; - -//-------------------------------------------------------------------- --(void)tmpunlockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; -{ -//TODO -#ifdef NeXT_Foundation_LIBRARY - [self unlock]; -#else - int result=0; -// LOGObjectFnStart(); - NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p", - self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner) - { - LOGException(@"NSLockException unlock: failed to unlock mutex (not locked). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"unlock: failed to lock mutex (not locked). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - } - else if (_mutex->owner!=objc_thread_id()) - { - LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"unlock: failed to lock mutex (not owner). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - } - else - { - result=objc_mutex_unlock(_mutex); - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result != 0) - { - NSDebugMLLog(@"low",@"AFT self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p", - self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - //NSDebugMLLog(@"low",@"UNLOCK PROBLEM"); - LOGException(@"NSLockException unlock: failed to unlock mutex (result %d!=0).%@. Called from %s in %s %d", - result, - MessageForMutexLockError(result), - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"unlock: failed to unlock mutex (result %d!=0).%@. Called from %s in %s %d", - result, - MessageForMutexLockError(result), - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - }; - }; - // LOGObjectFnStop(); -#endif -}; + return [super description]; +} @end - -NSString *NSRecursiveLockException = @"NSRecursiveLockException"; - -//==================================================================== -@implementation NSRecursiveLock (NSLockBD) - --(NSString*)description -{ - return [NSString stringWithFormat:@"<%s %p - ", - object_get_class_name(self), - (void*)self]; -}; +#endif //-------------------------------------------------------------------- --(BOOL)isLocked +static NSString * +volatileInternalDescription(NSLock *self) { - BOOL isLocked=YES; - if ([self tmptryLock]) +#ifdef GNUSTEP + struct objc_mutex *mutex = 0; + const char *type; + unsigned int size; + int offset; + + if (GSObjCFindVariable(self, "_mutex", &type, &size, &offset)) { - isLocked=NO; - [self unlock]; - }; + GSObjCGetVariable(self, offset, size, &mutex); + } + + if (mutex != 0) + { + return [NSString stringWithFormat: @"(%@ mutex:%p owner:%p depth:%d)", + self, mutex, mutex->owner, mutex->depth]; + } + else + { + return [NSString stringWithFormat: @"(%@ mutex:%p)", + self, mutex]; + } +#else + return [self description]; +#endif +} + +BOOL +loggedLockBeforeDateFromFunctionInFileInLine(id self, + BOOL try, + NSDate *limit, + const char *file, + const char *function, + long line) +{ + BOOL isLocked = YES; + NSThread *thread; + void *threadID = 0; + + thread = [NSThread currentThread]; +#ifdef GNUSTEP + threadID = objc_thread_id(); +#endif + NSDebugFLLog(@"locking", + @"%@ thread %@(%p) " + @"date:%@ file:%s function:%s line:%li " + @"lock:%@", + (try ? @"trying lock" : @"locking"), + thread, threadID, + limit, file, function, line, + volatileInternalDescription(self)); + + if (limit == nil) + { + if (try == YES) + { + isLocked = [self tryLock]; + } + else + { + NS_DURING + [self lock]; + NS_HANDLER + { + NSDebugFLLog(@"locking", + @"locking FAILED thread %@(%p) " + @"date:%@ file:%s function:%s line:%li " + @"lock:%@ " + @"excaption:%@ reason:%@ info:%@", + thread, threadID, + limit, file, function, line, + volatileInternalDescription(self), + [localException name], [localException reason], + [localException userInfo]); + [localException raise]; + } + NS_ENDHANDLER + } + } + else + { + isLocked = [self lockBeforeDate: limit]; + + if (try == NO && isLocked == NO) + { + NSString *name; + + NSDebugFLLog(@"locking", + @"tried lock FAILED thread %@(%p) " + @"date:%@ file:%s function:%s line:%li " + @"lock:%@ " + @"exception:%@ reason:%@ info:%@", + thread, threadID, + limit, file, function, line, + volatileInternalDescription(self)); + + name = NSStringFromClass([self class]); + name = [name stringByAppendingString:@"Exception"]; + + [NSException raise: name + format: @"lockBeforeDate (%@) failed", limit]; + } + } + + NSDebugFLLog(@"locking", + @"%@ %@ thread %@(%p) " + @"date:%@ file:%s function:%s line:%li " + @"result:%d lock:%@", + (try ? @"tried lock" : @"lock"), + (isLocked ? @"SUCCEEDED" : @"FAILED"), + thread, threadID, + limit, file, function, line, + isLocked, volatileInternalDescription(self)); + return isLocked; -}; +} -//-------------------------------------------------------------------- --(BOOL)tmplock +void +loggedUnlockFromFunctionInFileInLine(id self, + const char *file, + const char *function, + long line) { - return [self tmplockFromFunction:NULL - file:NULL - line:-1]; -}; + NSThread *thread; + void *threadID = 0; - -//-------------------------------------------------------------------- --(BOOL)tmplockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ -//TODO -#ifdef NeXT_Foundation_LIBRARY - return [self tryLock]; -#else - BOOL locked=NO; - int result=0; -// LOGObjectFnStart(); -// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner || _mutex->owner==objc_thread_id()) - { - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result == -1) - { - locked=NO; - LOGException(@"NSLockException lock: failed to lock mutex (result==-1). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"lock: failed to lock mutex (result==-1). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - } - else - { - locked=YES; - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - }; - } - else - { - LOGException(@"NSLockException lock: failed to lock mutex (not owner). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"lock: failed to lock mutex (not owner). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - }; - // NSDebugMLLog(@"low",@"locked=%d",(int)locked); - // LOGObjectFnStop(); - return locked; + thread = [NSThread currentThread]; +#ifdef GNUSTEP + threadID = objc_thread_id(); #endif -}; - -//-------------------------------------------------------------------- --(BOOL)tmptryLock -{ - return [self tmptryLockFromFunction:NULL - file:NULL - line:-1]; -}; - - -//-------------------------------------------------------------------- --(BOOL)tmptryLockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ -//TODO -#ifdef NeXT_Foundation_LIBRARY - return [self tryLock]; -#else - BOOL locked=NO; - int result=0; -// LOGObjectFnStart(); -// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner || _mutex->owner==objc_thread_id()) - { - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result == -1) - { - locked=NO; - } - else - { - locked=YES; - }; - }; - // NSDebugMLLog(@"low",@"locked=%d",(int)locked); - // LOGObjectFnStop(); - return locked; -#endif -}; - -//-------------------------------------------------------------------- --(BOOL)tmptryLockBeforeDate:(NSDate*)limit -{ - return [self tmptryLockBeforeDate:limit - fromFunction:NULL - file:NULL - line:-1]; -}; - -//-------------------------------------------------------------------- --(BOOL)tmptryLockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ - //TODO -#ifdef NeXT_Foundation_LIBRARY - return [self lockBeforeDate:limit]; -#else - BOOL locked=NO; - BOOL notOwner=NO; - int tryCount=0; - int result=0; -// LOGObjectFnStart(); -// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner || _mutex->owner==objc_thread_id()) - { - tryCount++; - notOwner=NO; - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result == -1) - locked=NO; - else - locked=YES; - } - else - notOwner=YES; - while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) - { - tryCount++; - //NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); - NSTimeIntervalSleep(0.010); - //NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner || _mutex->owner==objc_thread_id()) - { - notOwner=NO; - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result == -1) - { - if (tryCount%10==0) - NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p", - 10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id()); - locked=NO; - } - else - locked=YES; - } - else - notOwner=YES; - }; - // NSDebugMLLog(@"low",@"locked=%d",(int)locked); - if (locked) - { - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - } - else - { - NSDebugMLog(@"NSLock tmptryLockBeforeDate lock: failed to lock mutex before %@ (%s). Called from %s in %s %d", - limit, - notOwner ? "Not Owner" : "result==-1", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - }; - // LOGObjectFnStop(); - return locked; -#endif -}; - -//-------------------------------------------------------------------- --(BOOL)tmplockBeforeDate:(NSDate*)limit -{ - return [self tmplockBeforeDate:limit - fromFunction:NULL - file:NULL - line:-1]; -}; - -//-------------------------------------------------------------------- --(BOOL)tmplockBeforeDate:(NSDate*)limit - fromFunction:(const char*)fn - file:(const char*)file - line:(int)line -{ - //TODO -#ifdef NeXT_Foundation_LIBRARY - return [self lockBeforeDate:limit]; -#else - BOOL locked=NO; - BOOL notOwner=NO; - int tryCount=0; - int result=0; -// LOGObjectFnStart(); -// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner || _mutex->owner==objc_thread_id()) - { - tryCount++; - notOwner=NO; - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result == -1) - { - if (tryCount%10==0) - NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p", - 10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id()); - locked=NO; - } - else - locked=YES; - } - else - notOwner=YES; - - while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) - { - tryCount++; - //NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); - NSTimeIntervalSleep(0.010); - //NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (!_mutex->owner || _mutex->owner==objc_thread_id()) - { - notOwner=NO; - result=objc_mutex_trylock(_mutex); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result == -1) - { - if (tryCount%10==0) - NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p", - 10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id()); - locked=NO; - } - else - locked=YES; - } - else - notOwner=YES; - }; - // NSDebugMLLog(@"low",@"locked=%d",(int)locked); - if (locked) - { - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - } - else - { - LOGException(@"NSLockException lock: failed to lock mutex before date %@ (%s). Called from %s in %s %d", - limit, - notOwner ? "Not Owner" : "result==-1", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"lock: failed to lock mutex before date %@ (%s). Called from %s in %s %d", - limit, - notOwner ? "Not Owner" : "result==-1", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - }; -// LOGObjectFnStop(); - return locked; -#endif -}; - -//-------------------------------------------------------------------- --(void)tmpunlock -{ - [self tmpunlockFromFunction:NULL - file:NULL - line:-1]; -}; - -//-------------------------------------------------------------------- --(void)tmpunlockFromFunction:(const char*)fn - file:(const char*)file - line:(int)line; -{ - //TODO -#ifdef NeXT_Foundation_LIBRARY + NSDebugFLLog(@"locking", + @"unlock thread %@(%p) " + @"file:%s function:%s line:%li " + @"lock:%@", + thread, threadID, + file, function, line, + volatileInternalDescription(self)); [self unlock]; -#else - int result=0; -// LOGObjectFnStart(); -// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - if (_mutex->owner!=objc_thread_id()) - { - LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"unlock: failed to lock mutex (not owner). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - } - else - { - result=objc_mutex_unlock(_mutex); - //NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id()); - //NSDebugMLLog(@"low",@"result=%d",result); - if (result == -1) - { - LOGException(@"NSLockException unlock: failed to unlock mutex (result==-1). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line); - [NSException raise:NSLockException - format:@"unlock: failed to lock mutex (result==-1). Called from %s in %s %d", - fn ? fn : "Unknown", - file ? file : "Unknown", - line]; - }; - }; - // LOGObjectFnStop(); -#endif -}; -@end + NSDebugFLLog(@"locking", + @"unlock SUCCEEDED thread %@(%p) " + @"file:%s function:%s line:%li " + @"lock:%@", + thread, threadID, + file, function, line, + volatileInternalDescription(self)); + +} //==================================================================== @implementation NSArray (NSPerformSelectorWith2Objects) diff --git a/GSWeb.framework/NSObject+IVarAccess+PerformSel.m b/GSWeb.framework/NSObject+IVarAccess+PerformSel.m index 1eecf8e..d634f73 100644 --- a/GSWeb.framework/NSObject+IVarAccess+PerformSel.m +++ b/GSWeb.framework/NSObject+IVarAccess+PerformSel.m @@ -460,139 +460,156 @@ void IdToPData(const char* retType,id _value,void* pdata) NSObjectIVarsAccess* _ivarAccess=nil; NSMutableDictionary* _classCache=nil; LOGObjectFnStart(); - NSDebugMLLog(@"low",@"getIVarNamed %@ in %p %@ (superClass:%@)",name_,self,[self class],[self superclass]); + NSDebugMLLog(@"low",@"getIVarNamed %@ in %p %@ (superClass:%@)", + name_,self,[self class],[self superclass]); _class=[self class]; _classCache=[objectIVarAccessCache_Get objectForKey:_class]; if (!_classCache) + { + _cachindEnabled=![_class isIVarAccessCachingDisabled]; + if (_cachindEnabled) { - _cachindEnabled=![_class isIVarAccessCachingDisabled]; - if (_cachindEnabled) - { - if (!objectClassLock) - objectClassLock=[NSLock new]; - TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); - _classCache=[NSMutableDictionary dictionary]; - if (!objectIVarAccessCache_Get) - objectIVarAccessCache_Get=[NSMutableDictionary new]; - [objectIVarAccessCache_Get setObject:_classCache - forKey:_class]; - TmpUnlock(objectClassLock); - }; + if (!objectClassLock) + objectClassLock=[NSLock new]; + LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); + _classCache=[NSMutableDictionary dictionary]; + if (!objectIVarAccessCache_Get) + objectIVarAccessCache_Get=[NSMutableDictionary new]; + [objectIVarAccessCache_Get setObject:_classCache + forKey:_class]; + LoggedUnlock(objectClassLock); }; + }; if (_cachindEnabled) - _ivarAccess=[_classCache objectForKey:name_]; + _ivarAccess=[_classCache objectForKey:name_]; if (!_ivarAccess) + { + SEL sel=NULL; + _ivarAccess=[NSObjectIVarsAccess ivarAccess]; + sel=[self getSelectorWithFunctionTemplate:@"get%@" + forVariable:name_ + uppercaseFirstLetter:YES]; + if (!sel) + sel=[self getSelectorWithFunctionTemplate:@"%@" + forVariable:name_ + uppercaseFirstLetter:NO]; + NSDebugMLLog(@"low",@"getIVarNamed %@ in %@ %p sel=%p ", + name_,[self class],self,(void*)sel); + if (sel) { - SEL sel=NULL; - _ivarAccess=[NSObjectIVarsAccess ivarAccess]; - sel=[self getSelectorWithFunctionTemplate:@"get%@" - forVariable:name_ - uppercaseFirstLetter:YES]; - if (!sel) - sel=[self getSelectorWithFunctionTemplate:@"%@" - forVariable:name_ - uppercaseFirstLetter:NO]; - NSDebugMLLog(@"low",@"getIVarNamed %@ in %@ %p sel=%p ",name_,[self class],self,(void*)sel); - if (sel) - { - NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; - if ([_sig numberOfArguments]!=2) - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't get Variable named %@ in %@ %p (superClass:%@): fn args mismatch", - name_, - [self class], - self, - [self superclass]]; - } - else - { - const char* retType=[_sig methodReturnType]; - NSDebugMLLog(@"low",@"retType=%s",retType); - if (!retType) - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't get Variable named %@ in %@ %p (superClass:%@): fn unknown type", - name_, - [self class], - self, - [self superclass]]; - } - else - { - if (*retType==_C_ID) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_PerformSelector; - _ivarAccess->infos.selector=sel; - } - else - { - NSInvocation* _invocation = [NSInvocation invocationWithMethodSignature:_sig]; - NSDebugMLLog(@"low",@"_invocation methodSignature methodReturnType=%s",[[_invocation methodSignature] methodReturnType]); - [_invocation setSelector:sel]; - _ivarAccess->accessType=NSObjectIVarsAccessType_Invocation; - _ivarAccess->infos.invocation=_invocation; - NSAssert([_ivarAccess->infos.invocation selector],@"No Selector in Invocation"); - [_ivarAccess->infos.invocation retain]; - }; - }; - }; - } + NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; + if ([_sig numberOfArguments]!=2) + { + _exception =[NSException exceptionWithName: @"NSObject IVar" + format: @"Can't get Variable named " + @"%@ in %@ %p (superClass:%@): " + @"fn args mismatch", + name_, + [self class], + self, + [self superclass]]; + } else + { + const char* retType=[_sig methodReturnType]; + NSDebugMLLog(@"low",@"retType=%s",retType); + if (!retType) { - struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_,YES); - if (!ivar) - ivar=GSGetInstanceVariableStruct(self,name_,NO); - if (ivar) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; - _ivarAccess->infos.ivar=ivar; - } + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't get Variable named " + @"%@ in %@ %p (superClass:%@): " + @"fn unknown type", + name_, + [self class], + self, + [self superclass]]; + } + else + { + if (*retType==_C_ID) + { + _ivarAccess->accessType + = NSObjectIVarsAccessType_PerformSelector; + _ivarAccess->infos.selector=sel; + } else - { - NSDebugMLLog(@"low", - @"getIVarNamed %@ in %@ %p (superClass:%@) with objectForKey ", - name_, - [self class], - self, - [self superclass]); - if ([self respondsToSelector:@selector(objectForKey:)]) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_Dictionary; - } - else if ([self respondsToSelector:@selector(valueForKey:)]) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_EO; - } - else - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't get Variable named %@ in %@ %p (superClass:%@) with objectForKey", - name_, - [self class], - self, - [self superclass]]; - }; - }; + { + NSInvocation* _invocation + = [NSInvocation invocationWithMethodSignature:_sig]; + NSDebugMLLog(@"low", + @"_invocation methodSignature " + @"methodReturnType=%s", + [[_invocation methodSignature] + methodReturnType]); + [_invocation setSelector:sel]; + _ivarAccess->accessType + = NSObjectIVarsAccessType_Invocation; + _ivarAccess->infos.invocation=_invocation; + NSAssert([_ivarAccess->infos.invocation selector], + @"No Selector in Invocation"); + [_ivarAccess->infos.invocation retain]; + }; }; - - if (_exception) - _ivarAccess->accessType=NSObjectIVarsAccessType_Error; - if (_cachindEnabled) + }; + } + else + { + struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_,YES); + if (!ivar) + ivar=GSGetInstanceVariableStruct(self,name_,NO); + if (ivar) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; + _ivarAccess->infos.ivar=ivar; + } + else + { + NSDebugMLLog(@"low", + @"getIVarNamed %@ in %@ %p (superClass:%@) " + @"with objectForKey ", + name_, + [self class], + self, + [self superclass]); + if ([self respondsToSelector:@selector(objectForKey:)]) { - if (!objectClassLock) - objectClassLock=[NSLock new]; - TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); - [_classCache setObject:_ivarAccess - forKey:name_]; - TmpUnlock(objectClassLock); + _ivarAccess->accessType=NSObjectIVarsAccessType_Dictionary; + } + else if ([self respondsToSelector:@selector(valueForKey:)]) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_EO; + } + else + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't get Variable named " + @"%@ in %@ %p (superClass:%@) " + @"with objectForKey", + name_, + [self class], + self, + [self superclass]]; }; + }; }; + + if (_exception) + _ivarAccess->accessType=NSObjectIVarsAccessType_Error; + if (_cachindEnabled) + { + if (!objectClassLock) + objectClassLock=[NSLock new]; + LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); + [_classCache setObject:_ivarAccess + forKey:name_]; + LoggedUnlock(objectClassLock); + }; + }; if (_exception) - [_exception raise]; + [_exception raise]; else - _value=[self getIVarNamed:name_ - withCacheObject:_ivarAccess]; + _value=[self getIVarNamed:name_ + withCacheObject:_ivarAccess]; // LOGObjectFnStop(); return _value; }; @@ -708,163 +725,183 @@ void IdToPData(const char* retType,id _value,void* pdata) //-------------------------------------------------------------------- -(void)setIVarNamed:(NSString*)name_ - withValue:(id)value_ + withValue:(id)value_ { NSException* _exception=nil; BOOL _cachindEnabled=YES; Class _class=[self class]; NSObjectIVarsAccess* _ivarAccess=nil; - NSMutableDictionary* _classCache=[objectIVarAccessCache_Set objectForKey:_class]; + NSMutableDictionary* _classCache + = [objectIVarAccessCache_Set objectForKey:_class]; // LOGObjectFnStart(); - NSDebugMLLog(@"low",@"LOG setIVarNamed:%@ withValue:%@ in %p %@ (superClass:%@)",name_,value_,self,[self class],[self superclass]); + NSDebugMLLog(@"low", + @"LOG setIVarNamed:%@ withValue:%@ in %p %@ (superClass:%@)", + name_,value_,self,[self class],[self superclass]); if (!_classCache) + { + _cachindEnabled=![_class isIVarAccessCachingDisabled]; + if (_cachindEnabled) { - _cachindEnabled=![_class isIVarAccessCachingDisabled]; - if (_cachindEnabled) - { - if (!objectClassLock) - objectClassLock=[NSLock new]; - TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); - _classCache=[NSMutableDictionary dictionary]; - if (!objectIVarAccessCache_Set) - objectIVarAccessCache_Set=[NSMutableDictionary new]; - [objectIVarAccessCache_Set setObject:_classCache - forKey:_class]; - TmpUnlock(objectClassLock); - }; + if (!objectClassLock) + objectClassLock=[NSLock new]; + LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); + _classCache=[NSMutableDictionary dictionary]; + if (!objectIVarAccessCache_Set) + objectIVarAccessCache_Set=[NSMutableDictionary new]; + [objectIVarAccessCache_Set setObject:_classCache + forKey:_class]; + LoggedUnlock(objectClassLock); }; + }; if (_cachindEnabled) - _ivarAccess=[_classCache objectForKey:name_]; + _ivarAccess=[_classCache objectForKey:name_]; if (!_ivarAccess) + { + SEL sel=NULL; + NSDebugMLLog(@"low",@"Not ivarAccess for name:%@",name_); + _ivarAccess=[NSObjectIVarsAccess ivarAccess]; + // NSDebugMLLog(@"low",@"LOG setIVarNamed:%@ withValue:%@ in %@",name_,value_,[self class]); + sel=[self getSelectorWithFunctionTemplate:@"set%@:" + forVariable:name_ + uppercaseFirstLetter:YES]; + NSDebugMLLog(@"low", + @"sel=%ld (for %@ in %@)", + sel,name_,[self class]); + if (sel) { - SEL sel=NULL; - NSDebugMLLog(@"low",@"Not ivarAccess for name:%@",name_); - _ivarAccess=[NSObjectIVarsAccess ivarAccess]; - // NSDebugMLLog(@"low",@"LOG setIVarNamed:%@ withValue:%@ in %@",name_,value_,[self class]); - sel=[self getSelectorWithFunctionTemplate:@"set%@:" - forVariable:name_ - uppercaseFirstLetter:YES]; - NSDebugMLLog(@"low", - @"sel=%ld (for %@ in %@)", - sel,name_,[self class]); - if (sel) - { - NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; - if ([_sig numberOfArguments]!=3) - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't set Variable named %@ in %@ %p (superClass:%@) (fn Bad number of Arguments)", - name_, - [self class], - self, - [self superclass]]; - } - else - { - const char* type=[_sig getArgumentTypeAtIndex:2]; - if (!type) - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't set Variable named %@ in %@ %p (superClass:%@) (fn get argument type)", - name_, - [self class], - self, - [self superclass]]; - } - else - { - if (*type==_C_ID) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_PerformSelector; - _ivarAccess->infos.selector=sel; - NSDebugMLLog(@"low", - @"perform selector (IVar named :%@)", - name_); - } - else - { - NSInvocation* _invocation = [NSInvocation invocationWithMethodSignature:_sig]; - [_invocation setSelector:sel]; - _ivarAccess->accessType=NSObjectIVarsAccessType_Invocation; - _ivarAccess->infos.invocation=_invocation; - NSAssert([_ivarAccess->infos.invocation selector],@"No Selector in Invocation"); - [_ivarAccess->infos.invocation retain]; - NSDebugMLLog(@"low", - @"invocation (IVar named :%@)", - name_); - }; - }; - }; - } + NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; + if ([_sig numberOfArguments]!=3) + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't set Variable named %@ " + @"in %@ %p (superClass:%@) " + @"(fn Bad number of Arguments)", + name_, + [self class], + self, + [self superclass]]; + } else + { + const char* type=[_sig getArgumentTypeAtIndex:2]; + if (!type) { - struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_,YES); - if (!ivar) - ivar=GSGetInstanceVariableStruct(self,name_,NO); - if (ivar) - { - _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; - _ivarAccess->infos.ivar=ivar; - NSDebugMLLog(@"low", - @"direct (IVar named :%@)", - name_); - } + _exception + =[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't set Variable named %@ " + @"in %@ %p (superClass:%@) " + @"(fn get argument type)", + name_, + [self class], + self, + [self superclass]]; + } + else + { + if (*type==_C_ID) + { + _ivarAccess->accessType + = NSObjectIVarsAccessType_PerformSelector; + _ivarAccess->infos.selector=sel; + NSDebugMLLog(@"low", + @"perform selector (IVar named :%@)", + name_); + } else - { - BOOL _respondsToSetObject=NO; - BOOL _respondsToRemoveObject=NO; - NSDebugMLLog(@"low", - @"setIVarNamed %@ in %@ %p (superClass:%@) with dictionary ", - name_, - [self class], - self, - [self superclass]); - _respondsToSetObject=[self respondsToSelector:@selector(setObject:forKey:)]; - _respondsToRemoveObject=[self respondsToSelector:@selector(removeObjectForKey:)]; - if (_respondsToSetObject) - { - if (_respondsToRemoveObject) - _ivarAccess->accessType=NSObjectIVarsAccessType_DictionaryWithRemoveObject; - else - _ivarAccess->accessType=NSObjectIVarsAccessType_DictionaryWithoutRemoveObject; - } - else - { - BOOL _respondsToTakeValue=[self respondsToSelector:@selector(takeValue:forKey:)]; - if (_respondsToTakeValue) - _ivarAccess->accessType=NSObjectIVarsAccessType_EO; - else - { - _exception=[NSException exceptionWithName:@"NSObject IVar" - format:@"Can't set Variable named %@ in %@ %p (superClass:%@) value=%@", - name_, - [self class], - self, - [self superclass], - value_]; - }; - }; - }; + { + NSInvocation* _invocation + = [NSInvocation invocationWithMethodSignature:_sig]; + [_invocation setSelector:sel]; + _ivarAccess->accessType + = NSObjectIVarsAccessType_Invocation; + _ivarAccess->infos.invocation=_invocation; + NSAssert([_ivarAccess->infos.invocation selector], + @"No Selector in Invocation"); + [_ivarAccess->infos.invocation retain]; + NSDebugMLLog(@"low", + @"invocation (IVar named :%@)", + name_); + }; }; - - if (_exception) - _ivarAccess->accessType=NSObjectIVarsAccessType_Error; - if (_cachindEnabled) + }; + } + else + { + struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_,YES); + if (!ivar) + ivar=GSGetInstanceVariableStruct(self,name_,NO); + if (ivar) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; + _ivarAccess->infos.ivar=ivar; + NSDebugMLLog(@"low", + @"direct (IVar named :%@)", + name_); + } + else + { + BOOL _respondsToSetObject=NO; + BOOL _respondsToRemoveObject=NO; + NSDebugMLLog(@"low", + @"setIVarNamed %@ in %@ %p (superClass:%@) " + @"with dictionary ", + name_, + [self class], + self, + [self superclass]); + _respondsToSetObject + = [self respondsToSelector:@selector(setObject:forKey:)]; + _respondsToRemoveObject + =[self respondsToSelector:@selector(removeObjectForKey:)]; + if (_respondsToSetObject) { - if (!objectClassLock) - objectClassLock=[NSLock new]; - TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); - [_classCache setObject:_ivarAccess - forKey:name_]; - TmpUnlock(objectClassLock); + if (_respondsToRemoveObject) + _ivarAccess->accessType + = NSObjectIVarsAccessType_DictionaryWithRemoveObject; + else + _ivarAccess->accessType + = NSObjectIVarsAccessType_DictionaryWithoutRemoveObject; + } + else + { + BOOL _respondsToTakeValue + = [self respondsToSelector:@selector(takeValue:forKey:)]; + if (_respondsToTakeValue) + _ivarAccess->accessType=NSObjectIVarsAccessType_EO; + else + { + _exception + = [NSException exceptionWithName:@"NSObject IVar" + format:@"Can't set Variable named %@ " + @"in %@ %p (superClass:%@) value=%@", + name_, + [self class], + self, + [self superclass], + value_]; + }; }; + }; }; + + if (_exception) + _ivarAccess->accessType=NSObjectIVarsAccessType_Error; + if (_cachindEnabled) + { + if (!objectClassLock) + objectClassLock=[NSLock new]; + LoggedLockBeforeDate(objectClassLock, GSW_LOCK_LIMIT); + [_classCache setObject:_ivarAccess + forKey:name_]; + LoggedUnlock(objectClassLock); + }; + }; if (_exception) - [_exception raise]; + [_exception raise]; else - [self setIVarNamed:name_ - withValue:value_ - withCacheObject:_ivarAccess]; + [self setIVarNamed:name_ + withValue:value_ + withCacheObject:_ivarAccess]; // LOGObjectFnStop(); }; #endif diff --git a/Makefile.postamble b/Makefile.postamble index bd94efe..dcc929c 100644 --- a/Makefile.postamble +++ b/Makefile.postamble @@ -80,6 +80,7 @@ after-uninstall:: after-distclean:: rm -rf config.cache config.log config.status rm -rf config.h config.mak gsweb.make + rm -rf autom4te.cache gsweb.make: gsweb.make.in ./configure