Author: rfm
Date: Tue Jun 30 12:49:19 2015
New Revision: 38723
URL: http://svn.gna.org/viewcvs/gnustep?rev=38723&view=rev
Log:
Improve lock description
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Source/NSLock.m
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=38723&r1=38722&r2=38723&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Tue Jun 30 12:49:19 2015
@@ -6,7 +6,7 @@
Add test for pthread_mutex_t.__data.__owner
Update various tests to silence autoconf warnings.
* Source/NSLock.m: If available, use pthread_mutex_t.__data.__owner
- to print the owning thread ID when a lock is deadlocked.
+ to print the owning thread ID in the -description method.
2015-06-26 Riccardo Mottola <[email protected]>
Modified: libs/base/trunk/Source/NSLock.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSLock.m?rev=38723&r1=38722&r2=38723&view=diff
==============================================================================
--- libs/base/trunk/Source/NSLock.m (original)
+++ libs/base/trunk/Source/NSLock.m Tue Jun 30 12:49:19 2015
@@ -56,9 +56,35 @@
[_name release];\
[super dealloc];\
}
+
+#if defined(HAVE_PTHREAD_MUTEX_OWNER)
#define MDESCRIPTION \
- (NSString*) description\
{\
+ if (_mutex.__data.__owner)\
+ {\
+ if (_name == nil)\
+ {\
+ return [NSString stringWithFormat: @"%@ (locked by %d)",\
+ [super description], (int)_mutex.__data.__owner];\
+ }\
+ return [NSString stringWithFormat: @"%@ '%@' (locked by %d)",\
+ [super description], _name, (int)_mutex.__data.__owner];\
+ }\
+ else\
+ {\
+ if (_name == nil)\
+ {\
+ return [super description];\
+ }\
+ return [NSString stringWithFormat: @"%@ '%@'",\
+ [super description], _name];\
+ }\
+}
+#else
+#define MDESCRIPTION \
+- (NSString*) description\
+{\
if (_name == nil)\
{\
return [super description];\
@@ -66,11 +92,14 @@
return [NSString stringWithFormat: @"%@ '%@'",\
[super description], _name];\
}
+#endif
+
#define MFINALIZE \
- (void) finalize\
{\
pthread_mutex_destroy(&_mutex);\
}
+
#define MNAME \
- (void) setName: (NSString*)newName\
{\
@@ -80,6 +109,7 @@
{\
return _name;\
}
+
#define MLOCK \
- (void) lock\
{\
@@ -91,9 +121,10 @@
}\
if (EDEADLK == err)\
{\
- _NSLockError(self, _cmd, YES, &_mutex);\
- }\
-}
+ _NSLockError(self, _cmd, YES);\
+ }\
+}
+
#define MLOCKBEFOREDATE \
- (BOOL) lockBeforeDate: (NSDate*)limit\
{\
@@ -108,12 +139,14 @@
} while ([limit timeIntervalSinceNow] > 0);\
return NO;\
}
+
#define MTRYLOCK \
- (BOOL) tryLock\
{\
int err = pthread_mutex_trylock(&_mutex);\
return (0 == err) ? YES : NO;\
}
+
#define MUNLOCK \
- (void) unlock\
{\
@@ -132,15 +165,10 @@
/*
* OS X 10.5 compatibility function to allow debugging deadlock conditions.
*/
-void _NSLockError(id obj, SEL _cmd, BOOL stop, pthread_mutex_t *mutex)
-{
-#if defined(HAVE_PTHREAD_MUTEX_OWNER)
- NSLog(@"*** -[%@ %@]: deadlock (%@), held by thread %d", [obj class],
- NSStringFromSelector(_cmd), obj, mutex->__data.__owner);
-#else
+void _NSLockError(id obj, SEL _cmd, BOOL stop)
+{
NSLog(@"*** -[%@ %@]: deadlock (%@)", [obj class],
NSStringFromSelector(_cmd), obj);
-#endif
NSLog(@"*** Break on _NSLockError() to debug.");
if (YES == stop)
pthread_mutex_lock(&deadlock);
@@ -220,7 +248,7 @@
}
if (EDEADLK == err)
{
- _NSLockError(self, _cmd, NO, &_mutex);
+ _NSLockError(self, _cmd, NO);
}
sched_yield();
} while ([limit timeIntervalSinceNow] > 0);
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs