/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. #if DEBUG
  19. #import "GTMDefines.h"
  20. #import <Foundation/Foundation.h>
  21. // GTMAssertRunningOnMainThread will allow you to verify that you are
  22. // currently running on the main thread. This can be useful for checking
  23. // under DEBUG to make sure that code that requires being run on the main thread
  24. // is doing so. Use the GTMAssertRunningOnMainThread macro, don't use
  25. // the _GTMAssertRunningOnMainThread or _GTMIsRunningOnMainThread
  26. // helper functions.
  27. // On Leopard and above we can just use NSThread functionality.
  28. #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
  29. BOOL _GTMIsRunningOnMainThread(void);
  30. #else // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
  31. #import <Foundation/Foundation.h>
  32. GTM_INLINE BOOL _GTMIsRunningOnMainThread(void) {
  33. return [NSThread isMainThread];
  34. }
  35. #endif // MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
  36. GTM_INLINE void _GTMAssertRunningOnMainThread(const char *func,
  37. const char *file,
  38. int lineNum) {
  39. _GTMDevAssert(_GTMIsRunningOnMainThread(),
  40. @"%s not being run on main thread (%s - %d)",
  41. func, file, lineNum);
  42. }
  43. #define GTMAssertRunningOnMainThread() \
  44. (_GTMAssertRunningOnMainThread(__func__, __FILE__, __LINE__))
  45. #else // DEBUG
  46. #define GTMAssertRunningOnMainThread() do { } while (0)
  47. #endif // DEBUG