aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2016-04-29 13:51:31 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-04-29 13:51:31 -0400
commit7331352a30da15c92f942d07ed1a1a7db8e61250 (patch)
treef1b0df239232010b987b75eb1c3b940c95e499d8
parent91fdd6d09d6390b67ff3258b6418437dca11d6e1 (diff)
Update GTMDebugThreadValidation with general queue support.
-rw-r--r--AppKit/GTMGoogleSearch.m4
-rw-r--r--DebugUtils/GTMDebugThreadValidation.h59
-rw-r--r--DebugUtils/GTMDebugThreadValidation.m22
-rw-r--r--Foundation/GTMNSAppleScript+Handler.m15
4 files changed, 36 insertions, 64 deletions
diff --git a/AppKit/GTMGoogleSearch.m b/AppKit/GTMGoogleSearch.m
index 320c71d..9384ade 100644
--- a/AppKit/GTMGoogleSearch.m
+++ b/AppKit/GTMGoogleSearch.m
@@ -100,8 +100,10 @@ static LanguageDefaultInfo kLanguageListDefaultMappingTable[] = {
};
// the notification we use for syncing up instances in different processes
-static NSString *const kNotificationName
+#if GTM_GOOGLE_SEARCH_SUPPORTS_DISTRIBUTED_NOTIFICATIONS
+static NSString *const kNotificationName
= @"com.google.GoogleSearchAllApps.prefsWritten";
+#endif
// this is the bundle id we use for the pref file used for all apps
static CFStringRef const kAllAppsBuildIdentifier
diff --git a/DebugUtils/GTMDebugThreadValidation.h b/DebugUtils/GTMDebugThreadValidation.h
index 0636159..3f50f17 100644
--- a/DebugUtils/GTMDebugThreadValidation.h
+++ b/DebugUtils/GTMDebugThreadValidation.h
@@ -1,7 +1,7 @@
//
// GTMDebugThreadValidation.h
//
-// Copyright 2008 Google Inc.
+// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
@@ -16,40 +16,29 @@
// the License.
//
-#if DEBUG
#import "GTMDefines.h"
#import <Foundation/Foundation.h>
-// GTMAssertRunningOnMainThread will allow you to verify that you are
-// currently running on the main thread. This can be useful for checking
-// under DEBUG to make sure that code that requires being run on the main thread
-// is doing so. Use the GTMAssertRunningOnMainThread macro, don't use
-// the _GTMAssertRunningOnMainThread or _GTMIsRunningOnMainThread
-// helper functions.
-
-// On Leopard and above we can just use NSThread functionality.
-#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
-BOOL _GTMIsRunningOnMainThread(void);
-#else // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
-#import <Foundation/Foundation.h>
-GTM_INLINE BOOL _GTMIsRunningOnMainThread(void) {
- return [NSThread isMainThread];
-}
-#endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
-
-GTM_INLINE void _GTMAssertRunningOnMainThread(const char *func,
- const char *file,
- int lineNum) {
- _GTMDevAssert(_GTMIsRunningOnMainThread(),
- @"%s not being run on main thread (%s - %d)",
- func, file, lineNum);
-}
-
-#define GTMAssertRunningOnMainThread() \
- (_GTMAssertRunningOnMainThread(__func__, __FILE__, __LINE__))
-
-#else // DEBUG
-
-#define GTMAssertRunningOnMainThread() do { } while (0)
-
-#endif // DEBUG
+// GTMCheckCurrentQueue, GTMIsCurrentQueue
+//
+// GTMCheckCurrentQueue takes a target queue and uses _GTMDevAssert to
+// report if that is not the currently executing queue.
+//
+// GTMIsCurrentQueue takes a target queue and returns true if the target queue
+// is the currently executing dispatch queue. This can be passed to another
+// assertion call in debug builds; it should never be used in release code.
+//
+// The dispatch queue must have a label.
+#define GTMCheckCurrentQueue(targetQueue) \
+ _GTMDevAssert(GTMIsCurrentQueue(targetQueue), \
+ @"Current queue is %s (expected %s)", \
+ _GTMQueueName(DISPATCH_CURRENT_QUEUE_LABEL), \
+ _GTMQueueName(targetQueue))
+
+#define GTMIsCurrentQueue(targetQueue) \
+ (strcmp(_GTMQueueName(DISPATCH_CURRENT_QUEUE_LABEL), \
+ _GTMQueueName(targetQueue)) == 0)
+
+#define _GTMQueueName(queue) \
+ (strlen(dispatch_queue_get_label(queue)) > 0 ? \
+ dispatch_queue_get_label(queue) : "unnamed")
diff --git a/DebugUtils/GTMDebugThreadValidation.m b/DebugUtils/GTMDebugThreadValidation.m
index 30ee757..f2af8a0 100644
--- a/DebugUtils/GTMDebugThreadValidation.m
+++ b/DebugUtils/GTMDebugThreadValidation.m
@@ -1,7 +1,7 @@
//
// GTMDebugThreadValidation.m
//
-// Copyright 2008 Google Inc.
+// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
@@ -16,22 +16,4 @@
// the License.
//
-#import "GTMDebugThreadValidation.h"
-
-#if DEBUG && MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
-
-static NSThread *gGTMMainThread = nil;
-
-static __attribute__((constructor)) void _GTMInitThread(void) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- gGTMMainThread = [NSThread currentThread];
- [gGTMMainThread retain];
- [pool release];
-}
-
-
-BOOL _GTMIsRunningOnMainThread(void) {
- return [[NSThread currentThread] isEqual:gGTMMainThread];
-}
-
-#endif // DEBUG && MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
+// No implementation source currently needed.
diff --git a/Foundation/GTMNSAppleScript+Handler.m b/Foundation/GTMNSAppleScript+Handler.m
index e17ba91..850de58 100644
--- a/Foundation/GTMNSAppleScript+Handler.m
+++ b/Foundation/GTMNSAppleScript+Handler.m
@@ -22,7 +22,6 @@
#import "GTMNSAppleEventDescriptor+Handler.h"
#import "GTMFourCharCode.h"
#import "GTMMethodCheck.h"
-#import "GTMDebugThreadValidation.h"
// Keys for passing AppleScript calls from other threads to the main thread
// and back through gtm_internalExecuteAppleEvent:
@@ -326,7 +325,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:);
}
- (NSAppleEventDescriptor*)gtm_valueDescriptorForProperty:(id)property {
- GTMAssertRunningOnMainThread();
+ _GTMDevAssert([NSThread isMainThread], @"Requires main thread.");
OSAError error = paramErr;
NSAppleEventDescriptor *desc = nil;
NSAppleEventDescriptor *propertyName
@@ -377,7 +376,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:);
}
- (NSSet*)gtm_scriptHandlers {
- GTMAssertRunningOnMainThread();
+ _GTMDevAssert([NSThread isMainThread], @"Requires main thread.");
AEDescList names = { typeNull, NULL };
NSArray *array = nil;
ComponentInstance component = NULL;
@@ -396,7 +395,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:);
}
- (NSSet*)gtm_scriptProperties {
- GTMAssertRunningOnMainThread();
+ _GTMDevAssert([NSThread isMainThread], @"Requires main thread.");
AEDescList names = { typeNull, NULL };
NSArray *array = nil;
ComponentInstance component = NULL;
@@ -415,7 +414,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:);
}
- (OSAID)gtm_genericID:(OSAID)osaID forComponent:(ComponentInstance)component {
- GTMAssertRunningOnMainThread();
+ _GTMDevAssert([NSThread isMainThread], @"Requires main thread.");
ComponentInstance genericComponent = [NSAppleScript _defaultScriptingComponent];
OSAID exactID = osaID;
OSAError error = OSARealToGenericID(genericComponent, &exactID, component);
@@ -428,7 +427,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:);
- (NSAppleEventDescriptor*)descForScriptID:(OSAID)osaID
component:(ComponentInstance)component {
- GTMAssertRunningOnMainThread();
+ _GTMDevAssert([NSThread isMainThread], @"Requires main thread.");
NSAppleEventDescriptor *desc = nil;
// If we have a script, return a typeGTMOSAID, otherwise convert it to
// it's default AEDesc using OSACoerceToDesc with typeWildCard.
@@ -468,7 +467,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:);
}
- (OSAID)gtm_realIDAndComponent:(ComponentInstance*)component {
- GTMAssertRunningOnMainThread();
+ _GTMDevAssert([NSThread isMainThread], @"Requires main thread.");
if (![self isCompiled]) {
NSDictionary *error;
if (![self compileAndReturnError:&error]) {
@@ -487,7 +486,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:);
}
- (void)gtm_internalExecuteAppleEvent:(NSMutableDictionary *)data {
- GTMAssertRunningOnMainThread();
+ _GTMDevAssert([NSThread isMainThread], @"Requires main thread.");
NSDictionary *error = nil;
if (![self isCompiled]) {
[self compileAndReturnError:&error];