mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
Improve lock description
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38723 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7de51ac321
commit
24f1c5b06c
2 changed files with 37 additions and 9 deletions
|
@ -6,7 +6,7 @@
|
||||||
Add test for pthread_mutex_t.__data.__owner
|
Add test for pthread_mutex_t.__data.__owner
|
||||||
Update various tests to silence autoconf warnings.
|
Update various tests to silence autoconf warnings.
|
||||||
* Source/NSLock.m: If available, use pthread_mutex_t.__data.__owner
|
* 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 <rm@gnu.org>
|
2015-06-26 Riccardo Mottola <rm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,32 @@
|
||||||
[_name release];\
|
[_name release];\
|
||||||
[super dealloc];\
|
[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 \
|
#define MDESCRIPTION \
|
||||||
- (NSString*) description\
|
- (NSString*) description\
|
||||||
{\
|
{\
|
||||||
|
@ -66,11 +92,14 @@
|
||||||
return [NSString stringWithFormat: @"%@ '%@'",\
|
return [NSString stringWithFormat: @"%@ '%@'",\
|
||||||
[super description], _name];\
|
[super description], _name];\
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MFINALIZE \
|
#define MFINALIZE \
|
||||||
- (void) finalize\
|
- (void) finalize\
|
||||||
{\
|
{\
|
||||||
pthread_mutex_destroy(&_mutex);\
|
pthread_mutex_destroy(&_mutex);\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MNAME \
|
#define MNAME \
|
||||||
- (void) setName: (NSString*)newName\
|
- (void) setName: (NSString*)newName\
|
||||||
{\
|
{\
|
||||||
|
@ -80,6 +109,7 @@
|
||||||
{\
|
{\
|
||||||
return _name;\
|
return _name;\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MLOCK \
|
#define MLOCK \
|
||||||
- (void) lock\
|
- (void) lock\
|
||||||
{\
|
{\
|
||||||
|
@ -91,9 +121,10 @@
|
||||||
}\
|
}\
|
||||||
if (EDEADLK == err)\
|
if (EDEADLK == err)\
|
||||||
{\
|
{\
|
||||||
_NSLockError(self, _cmd, YES, &_mutex);\
|
_NSLockError(self, _cmd, YES);\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MLOCKBEFOREDATE \
|
#define MLOCKBEFOREDATE \
|
||||||
- (BOOL) lockBeforeDate: (NSDate*)limit\
|
- (BOOL) lockBeforeDate: (NSDate*)limit\
|
||||||
{\
|
{\
|
||||||
|
@ -108,12 +139,14 @@
|
||||||
} while ([limit timeIntervalSinceNow] > 0);\
|
} while ([limit timeIntervalSinceNow] > 0);\
|
||||||
return NO;\
|
return NO;\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MTRYLOCK \
|
#define MTRYLOCK \
|
||||||
- (BOOL) tryLock\
|
- (BOOL) tryLock\
|
||||||
{\
|
{\
|
||||||
int err = pthread_mutex_trylock(&_mutex);\
|
int err = pthread_mutex_trylock(&_mutex);\
|
||||||
return (0 == err) ? YES : NO;\
|
return (0 == err) ? YES : NO;\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MUNLOCK \
|
#define MUNLOCK \
|
||||||
- (void) unlock\
|
- (void) unlock\
|
||||||
{\
|
{\
|
||||||
|
@ -132,15 +165,10 @@ static pthread_mutexattr_t attr_recursive;
|
||||||
/*
|
/*
|
||||||
* OS X 10.5 compatibility function to allow debugging deadlock conditions.
|
* OS X 10.5 compatibility function to allow debugging deadlock conditions.
|
||||||
*/
|
*/
|
||||||
void _NSLockError(id obj, SEL _cmd, BOOL stop, pthread_mutex_t *mutex)
|
void _NSLockError(id obj, SEL _cmd, BOOL stop)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_PTHREAD_MUTEX_OWNER)
|
|
||||||
NSLog(@"*** -[%@ %@]: deadlock (%@), held by thread %d", [obj class],
|
|
||||||
NSStringFromSelector(_cmd), obj, mutex->__data.__owner);
|
|
||||||
#else
|
|
||||||
NSLog(@"*** -[%@ %@]: deadlock (%@)", [obj class],
|
NSLog(@"*** -[%@ %@]: deadlock (%@)", [obj class],
|
||||||
NSStringFromSelector(_cmd), obj);
|
NSStringFromSelector(_cmd), obj);
|
||||||
#endif
|
|
||||||
NSLog(@"*** Break on _NSLockError() to debug.");
|
NSLog(@"*** Break on _NSLockError() to debug.");
|
||||||
if (YES == stop)
|
if (YES == stop)
|
||||||
pthread_mutex_lock(&deadlock);
|
pthread_mutex_lock(&deadlock);
|
||||||
|
@ -220,7 +248,7 @@ MLOCK
|
||||||
}
|
}
|
||||||
if (EDEADLK == err)
|
if (EDEADLK == err)
|
||||||
{
|
{
|
||||||
_NSLockError(self, _cmd, NO, &_mutex);
|
_NSLockError(self, _cmd, NO);
|
||||||
}
|
}
|
||||||
sched_yield();
|
sched_yield();
|
||||||
} while ([limit timeIntervalSinceNow] > 0);
|
} while ([limit timeIntervalSinceNow] > 0);
|
||||||
|
|
Loading…
Reference in a new issue