aboutsummaryrefslogtreecommitdiff
path: root/DebugUtils
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 /DebugUtils
parent91fdd6d09d6390b67ff3258b6418437dca11d6e1 (diff)
Update GTMDebugThreadValidation with general queue support.
Diffstat (limited to 'DebugUtils')
-rw-r--r--DebugUtils/GTMDebugThreadValidation.h59
-rw-r--r--DebugUtils/GTMDebugThreadValidation.m22
2 files changed, 26 insertions, 55 deletions
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.