Author: rfm
Date: Wed Jul 8 14:54:15 2015
New Revision: 38768
URL: http://svn.gna.org/viewcvs/gnustep?rev=38768&view=rev
Log:
Thread diagnositc changes
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Headers/Foundation/NSLock.h
libs/base/trunk/Source/GSPrivate.h
libs/base/trunk/Source/NSLock.m
libs/base/trunk/Source/NSLog.m
libs/base/trunk/Source/NSThread.m
libs/base/trunk/Tests/base/NSLock/RecursiveLock.m
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=38768&r1=38767&r2=38768&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Wed Jul 8 14:54:15 2015
@@ -1,3 +1,11 @@
+2015-07-08 Richard Frith-Macdonald <[email protected]>
+
+ * Headers/Foundation/NSLock.h:
+ * Source/NSLock.m:
+ Add extension method -isLockedByCurrentThread for debug purposes.
+ Also make description report the OS thread id of the thread which
+ holds the lock (if any).
+
2015-07-08 Riccardo Mottola <[email protected]>
* Headers/GNUstepBase/GSConfig.h.in
Modified: libs/base/trunk/Headers/Foundation/NSLock.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Headers/Foundation/NSLock.h?rev=38768&r1=38767&r2=38768&view=diff
==============================================================================
--- libs/base/trunk/Headers/Foundation/NSLock.h (original)
+++ libs/base/trunk/Headers/Foundation/NSLock.h Wed Jul 8 14:54:15 2015
@@ -78,20 +78,27 @@
#endif
}
+#if !NO_GNUSTEP
+/** Report whether this lock is held by the current thread.<br />
+ * Raises an exception if this is not supported by the system lock mechanism.
+ */
+- (BOOL) isLockedByCurrentThread;
+#endif
+
+/**
+ * Try to acquire lock and return before limit, YES if succeeded, NO if not.
+ */
+- (BOOL) lockBeforeDate: (NSDate*)limit;
+
+/**
+ * Block until acquiring lock.
+ */
+- (void) lock;
+
/**
* Try to acquire lock and return immediately, YES if succeeded, NO if not.
*/
- (BOOL) tryLock;
-
-/**
- * Try to acquire lock and return before limit, YES if succeeded, NO if not.
- */
-- (BOOL) lockBeforeDate: (NSDate*)limit;
-
-/**
- * Block until acquiring lock.
- */
-- (void) lock;
/**
* Relinquish lock.
@@ -183,6 +190,13 @@
*/
- (NSInteger) condition;
+#if !NO_GNUSTEP
+/** Report whether this lock is held by the current thread.<br />
+ * Raises an exception if this is not supported by the system lock mechanism.
+ */
+- (BOOL) isLockedByCurrentThread;
+#endif
+
/*
* Acquiring and releasing the lock.
*/
@@ -265,6 +279,13 @@
#endif
}
+#if !NO_GNUSTEP
+/** Report whether this lock is held by the current thread.<br />
+ * Raises an exception if this is not supported by the system lock mechanism.
+ */
+- (BOOL) isLockedByCurrentThread;
+#endif
+
/**
* Try to acquire lock regardless of condition and return immediately, YES if
* succeeded, NO if not.
Modified: libs/base/trunk/Source/GSPrivate.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSPrivate.h?rev=38768&r1=38767&r2=38768&view=diff
==============================================================================
--- libs/base/trunk/Source/GSPrivate.h (original)
+++ libs/base/trunk/Source/GSPrivate.h Wed Jul 8 14:54:15 2015
@@ -571,7 +571,7 @@
GSPrivateFinishHash(uint32_t s0, uint32_t s1, uint32_t totalLength)
GS_ATTRIB_PRIVATE;
-/* Return the current thread ID as an unsigned long.
+/* Return the current thread ID as an NSUInteger.
* Ideally, we use the operating-system's notion of a thread ID so
* that external process monitoring software will be using the same
* value that we log. If we don't know the system's mechanism, we
@@ -579,7 +579,7 @@
* it makes no sense externally, it can still be used to show that
* different threads generated different logs.
*/
-unsigned long
+NSUInteger
GSPrivateThreadID()
GS_ATTRIB_PRIVATE;
Modified: libs/base/trunk/Source/NSLock.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSLock.m?rev=38768&r1=38767&r2=38768&view=diff
==============================================================================
--- libs/base/trunk/Source/NSLock.m (original)
+++ libs/base/trunk/Source/NSLock.m Wed Jul 8 14:54:15 2015
@@ -58,6 +58,7 @@
}
#if defined(HAVE_PTHREAD_MUTEX_OWNER)
+
#define MDESCRIPTION \
- (NSString*) description\
{\
@@ -65,11 +66,11 @@
{\
if (_name == nil)\
{\
- return [NSString stringWithFormat: @"%@ (locked by %d)",\
- [super description], (int)_mutex.__data.__owner];\
+ return [NSString stringWithFormat: @"%@ (locked by %llu)",\
+ [super description], (NSUInteger)_mutex.__data.__owner];\
}\
- return [NSString stringWithFormat: @"%@ '%@' (locked by %d)",\
- [super description], _name, (int)_mutex.__data.__owner];\
+ return [NSString stringWithFormat: @"%@ '%@' (locked by %llu)",\
+ [super description], _name, (NSUInteger)_mutex.__data.__owner];\
}\
else\
{\
@@ -81,7 +82,18 @@
[super description], _name];\
}\
}
+
+#define MISLOCKED \
+- (BOOL) isLockedByCurrentThread\
+{\
+ if (GSPrivateThreadID() == (NSUInteger)_mutex.__data.__owner)\
+ return YES;\
+ else\
+ return NO; \
+}
+
#else
+
#define MDESCRIPTION \
- (NSString*) description\
{\
@@ -92,6 +104,14 @@
return [NSString stringWithFormat: @"%@ '%@'",\
[super description], _name];\
}
+
+#define MISLOCKED \
+- (BOOL) isLockedByCurrentThread\
+{\
+ [NSException raise: NSGenericException format: @"Not supported"];\
+ return NO;\
+}
+
#endif
#define MFINALIZE \
@@ -235,6 +255,7 @@
return self;
}
+MISLOCKED
MLOCK
- (BOOL) lockBeforeDate: (NSDate*)limit
@@ -283,6 +304,7 @@
return self;
}
+MISLOCKED
MLOCK
MLOCKBEFOREDATE
MNAME
@@ -328,6 +350,7 @@
return self;
}
+MISLOCKED
MLOCK
MLOCKBEFOREDATE
MNAME
@@ -414,6 +437,11 @@
return self;
}
+- (BOOL) isLockedByCurrentThread
+{
+ return [_condition isLockedByCurrentThread];
+}
+
- (void) lock
{
[_condition lock];
Modified: libs/base/trunk/Source/NSLog.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSLog.m?rev=38768&r1=38767&r2=38768&view=diff
==============================================================================
--- libs/base/trunk/Source/NSLog.m (original)
+++ libs/base/trunk/Source/NSLog.m Wed Jul 8 14:54:15 2015
@@ -368,12 +368,13 @@
{
if (nil != threadName)
{
- [prefix appendFormat: @"[thread:%lu,%@] ",
- GSPrivateThreadID(), threadName];
+ [prefix appendFormat: @"[thread:%llu,%@] ",
+ (unsigned long long)GSPrivateThreadID(), threadName];
}
else
{
- [prefix appendFormat: @"[thread:%lu] ", GSPrivateThreadID()];
+ [prefix appendFormat: @"[thread:%llu] ",
+ (unsigned long long)GSPrivateThreadID()];
}
}
else
@@ -397,13 +398,13 @@
[prefix appendString: [[NSProcessInfo processInfo] processName]];
if (nil == threadName)
{
- [prefix appendFormat: @"[%d:%lu] ",
- pid, GSPrivateThreadID()];
+ [prefix appendFormat: @"[%d:%llu] ",
+ pid, (unsigned long long)GSPrivateThreadID()];
}
else
{
- [prefix appendFormat: @"[%d:%lu,%@] ",
- pid, GSPrivateThreadID(), threadName];
+ [prefix appendFormat: @"[%d:%llu,%@] ",
+ pid, (unsigned long long)GSPrivateThreadID(), threadName];
}
}
Modified: libs/base/trunk/Source/NSThread.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSThread.m?rev=38768&r1=38767&r2=38768&view=diff
==============================================================================
--- libs/base/trunk/Source/NSThread.m (original)
+++ libs/base/trunk/Source/NSThread.m Wed Jul 8 14:54:15 2015
@@ -111,17 +111,17 @@
* it makes no sense externally, it can still be used to show that
* different threads generated different logs.
*/
-unsigned long
+NSUInteger
GSPrivateThreadID()
{
#if defined(__MINGW__)
- return (unsigned long)GetCurrentThreadId();
+ return (NSUInteger)GetCurrentThreadId();
#elif defined(HAVE_GETTID)
- return (unsigned long)syscall(SYS_gettid);
+ return (NSUInteger)syscall(SYS_gettid);
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
return pthread_getthreadid_np();
#else
- return (unsigned long)GSCurrentThread();
+ return (NSUInteger)GSCurrentThread();
#endif
}
@@ -796,8 +796,8 @@
- (NSString*) description
{
- return [NSString stringWithFormat: @"%@{name = %@, num = %lu}",
- [super description], _name, GSPrivateThreadID()];
+ return [NSString stringWithFormat: @"%@{name = %@, num = %llu}",
+ [super description], _name, (unsigned long long)GSPrivateThreadID()];
}
- (id) init
Modified: libs/base/trunk/Tests/base/NSLock/RecursiveLock.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/NSLock/RecursiveLock.m?rev=38768&r1=38767&r2=38768&view=diff
==============================================================================
--- libs/base/trunk/Tests/base/NSLock/RecursiveLock.m (original)
+++ libs/base/trunk/Tests/base/NSLock/RecursiveLock.m Wed Jul 8 14:54:15 2015
@@ -6,23 +6,47 @@
NSAutoreleasePool *arp = [NSAutoreleasePool new];
BOOL ret;
NSLock *lock = [NSRecursiveLock new];
+
ret = [lock tryLock];
if (ret)
[lock unlock];
PASS(ret, "NSRecursiveLock with tryLock, then unlocking");
- ASSIGN(lock,[NSRecursiveLock new]);
- ret = [lock lockBeforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
+ ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
if (ret)
[lock unlock];
PASS(ret, "NSRecursiveLock lockBeforeDate: works");
- ASSIGN(lock,[NSRecursiveLock new]);
- [lock tryLock];
- ret = [lock lockBeforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
+ ret = [lock tryLock];
if (ret)
- [lock unlock];
+ {
+ ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow:1]];
+ if (ret)
+ {
+ [lock unlock];
+ }
+ [lock unlock];
+ }
PASS(ret, "NSRecursiveLock lockBeforeDate: with NSRecursiveLock returns
YES");
+
+#if defined(GNUSTEP_BASE_LIBRARY)
+ NS_DURING
+ {
+ PASS([lock isLockedByCurrentThread] == NO,
+ "NSRecursiveLock isLockedByCurrentThread returns NO when not locked");
+ [lock lock];
+ PASS([lock isLockedByCurrentThread] == YES,
+ "NSRecursiveLock isLockedByCurrentThread returns YES when not locked");
+ [lock unlock];
+ PASS([lock isLockedByCurrentThread] == NO,
+ "NSRecursiveLock isLockedByCurrentThread returns NO when unlocked");
+ }
+ NS_HANDLER
+ {
+ NSLog(@"-isLockedByCurrentThread not supported");
+ }
+ NS_ENDHANDLER
+#endif
[arp release]; arp = nil;
return 0;
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs