Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

cocoa touch - checking for equality on dispatch_queue_t

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

dispatch_queue_get_label(dispatch_queue_t queue);

and pass DISPATCH_CURRENT_QUEUE_LABEL for get label of current queue

For specific:

dispatch_queue_get_specific(dispatch_queue_t queue, const void *key);

for get you queue specific and

dispatch_get_specific(const void *key);

for current

It's require to set one or both of label and specific for your queue. For example when you create it

dispatch_queue_create(const char *label, dispatch_queue_attr_t attr);

or using setters for specific

dispatch_queue_set_specific(dispatch_queue_t queue, const void *key,
    void *context, dispatch_function_t destructor);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...