[google-toolbox-for-mac] r585 committed - [Author: aharper]...

3 views
Skip to first unread message

google-tool...@googlecode.com

unread,
Nov 14, 2012, 8:00:21 PM11/14/12
to google-tool...@googlegroups.com
Revision: 585
Author: gtm.daemon
Date: Wed Nov 14 17:00:14 2012
Log: [Author: aharper]

Exclude on 10.4 and only set name when pthread_setname_np is available
(10.6 and later).

R=dmaclach,thomasvl
APPROVED=dmaclach
DELTA=19 (17 added, 0 deleted, 2 changed)
http://code.google.com/p/google-toolbox-for-mac/source/detail?r=585

Modified:
/trunk/Foundation/GTMNSThread+Blocks.h
/trunk/Foundation/GTMNSThread+Blocks.m

=======================================
--- /trunk/Foundation/GTMNSThread+Blocks.h Wed Nov 14 11:30:11 2012
+++ /trunk/Foundation/GTMNSThread+Blocks.h Wed Nov 14 17:00:14 2012
@@ -37,6 +37,10 @@

#endif // NS_BLOCKS_AVAILABLE

+// [NSObject performSelector:onThread:...] 10.5 and later, so this makes no
+// sense on any earlier SDK.
+#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >=
MAC_OS_X_VERSION_10_5)
+
// A simple thread that does nothing but handle performBlock and
// performSelector calls.
@interface GTMSimpleWorkerThread : NSThread {
@@ -47,3 +51,5 @@
// Will stop the thread.
- (void)stop;
@end
+
+#endif // GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >=
MAC_OS_X_VERSION_10_5)
=======================================
--- /trunk/Foundation/GTMNSThread+Blocks.m Wed Nov 14 13:00:10 2012
+++ /trunk/Foundation/GTMNSThread+Blocks.m Wed Nov 14 17:00:14 2012
@@ -18,7 +18,11 @@

#import "GTMNSThread+Blocks.h"

-#include <pthread.h>
+#import <pthread.h>
+#import <dlfcn.h>
+
+// Only available 10.6 and later.
+typedef int (*pthread_setname_np_Ptr)(const char*);

#if NS_BLOCKS_AVAILABLE

@@ -52,12 +56,17 @@

#endif // NS_BLOCKS_AVAILABLE

+#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >=
MAC_OS_X_VERSION_10_5)
+
@implementation GTMSimpleWorkerThread

- (void)setThreadDebuggerName:(NSString *)name {
// [NSThread setName:] doesn't actually set the name in such a way that
the
// debugger can see it. So we handle it here instead.
- pthread_setname_np([name UTF8String]);
+ // pthread_setname_np only available 10.6 and later, look up dynamically.
+ pthread_setname_np_Ptr setName =
dlsym(RTLD_DEFAULT, "pthread_setname_np");
+ if (!setName) return;
+ setName([name UTF8String]);
}

- (void)main {
@@ -90,3 +99,5 @@
}

@end
+
+#endif // GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >=
MAC_OS_X_VERSION_10_5)
Reply all
Reply to author
Forward
0 new messages