PageRenderTime 13ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/DebugUtils/GTMDebugThreadValidation.h

http://macfuse.googlecode.com/
C++ Header | 55 lines | 23 code | 8 blank | 24 comment | 1 complexity | bf5c648dbc1119f9ad1860c2d8414be4 MD5 | raw file
 1//
 2//  GTMDebugThreadValidation.h
 3//
 4//  Copyright 2008 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9// 
10//  http://www.apache.org/licenses/LICENSE-2.0
11// 
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#if DEBUG
20#import "GTMDefines.h"
21#import <Foundation/Foundation.h>
22
23// GTMAssertRunningOnMainThread will allow you to verify that you are
24// currently running on the main thread. This can be useful for checking
25// under DEBUG to make sure that code that requires being run on the main thread
26// is doing so. Use the GTMAssertRunningOnMainThread macro, don't use
27// the _GTMAssertRunningOnMainThread or _GTMIsRunningOnMainThread
28// helper functions.
29
30// On Leopard and above we can just use NSThread functionality.
31#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
32BOOL _GTMIsRunningOnMainThread(void);
33#else  // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
34#import <Foundation/Foundation.h>
35GTM_INLINE BOOL _GTMIsRunningOnMainThread(void) { 
36  return [NSThread isMainThread]; 
37}
38#endif  // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
39
40GTM_INLINE void _GTMAssertRunningOnMainThread(const char *func,
41                                              const char *file, 
42                                              int lineNum) { 
43  _GTMDevAssert(_GTMIsRunningOnMainThread(), 
44                @"%s not being run on main thread (%s - %d)",
45                func, file, lineNum);
46}
47
48#define GTMAssertRunningOnMainThread() \
49  (_GTMAssertRunningOnMainThread(__func__, __FILE__, __LINE__))
50
51#else // DEBUG
52
53#define GTMAssertRunningOnMainThread() do { } while (0)
54
55#endif // DEBUG