GTMDebugThreadValidation.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // GTMDebugThreadValidation.h
  3. //
  4. // Copyright 2016 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. #import "GTMDefines.h"
  19. #import <Foundation/Foundation.h>
  20. // GTMCheckCurrentQueue, GTMIsCurrentQueue
  21. //
  22. // GTMCheckCurrentQueue takes a target queue and uses _GTMDevAssert to
  23. // report if that is not the currently executing queue.
  24. //
  25. // GTMIsCurrentQueue takes a target queue and returns true if the target queue
  26. // is the currently executing dispatch queue. This can be passed to another
  27. // assertion call in debug builds; it should never be used in release code.
  28. //
  29. // The dispatch queue must have a label.
  30. #define GTMCheckCurrentQueue(targetQueue) \
  31. _GTMDevAssert(GTMIsCurrentQueue(targetQueue), \
  32. @"Current queue is %s (expected %s)", \
  33. _GTMQueueName(DISPATCH_CURRENT_QUEUE_LABEL), \
  34. _GTMQueueName(targetQueue))
  35. #define GTMIsCurrentQueue(targetQueue) \
  36. (strcmp(_GTMQueueName(DISPATCH_CURRENT_QUEUE_LABEL), \
  37. _GTMQueueName(targetQueue)) == 0)
  38. #define _GTMQueueName(queue) \
  39. (strlen(dispatch_queue_get_label(queue)) > 0 ? \
  40. dispatch_queue_get_label(queue) : "unnamed")