How can I check for equality between dispatch_queue_t vars?
dispatch_queue_t currentQueue = dispatch_get_current_queue();
dispatch_queue_t mainQueue = dispatch_get_main_queue();
if (currentQueue == mainQueue) {
}
from the docs:
typedef struct dispatch_queue_s *dispatch_queue_t;
I'm not sure but does this mean that it's a pointer to a dispatch_queue_s struct?
Since I can't check equality on pointers, I'm not sure how can I check if a dispatch_queue_t is the same as another?
This depends on the queue you're on. In this particular case use:
In general, you can use
dispatch_get_current_queue()
to test which queue your're on. In that case you can use the==
operator to do so. To quote the Dispatch Queues page in Apple's Concurrency Programming Guide:Since dispatch_get_current_queue() is deprecated, we could compare current and your queues by their labels (or specifics as @jkh suggested)
For label use
and pass DISPATCH_CURRENT_QUEUE_LABEL for get label of current queue
For specific:
for get you queue specific and
for current
It's require to set one or both of label and specific for your queue. For example when you create it
or using setters for specific
First part of answer: What are you trying to do? Why do you need to compare queues? If all you need to do is "tag" a queue with some specific piece of metadata, consider using dispatch_queue_{set, get}_specific() instead.
Second part of answer: Don't use dispatch_get_current_queue() for, well, anything. It's just for debugging purposes and its use has always been discouraged.