1 #include <dispatch/dispatch.h>
8 #include "dispatch_test.h"
13 test_start("Dispatch Queue Finalizer");
16 void* ctxt_magic
= (void*)((uintptr_t)arc4random() << 32 | arc4random());
18 void* ctxt_magic
= (void*)arc4random();
21 dispatch_queue_attr_t attr
= dispatch_queue_attr_create();
22 test_ptr_notnull("dispatch_queue_attr_create", attr
);
24 __block
long finalizer_ran
= 0;
26 res
= dispatch_queue_attr_set_finalizer(attr
, ^(dispatch_queue_t dq
) {
27 void* ctxt
= dispatch_queue_get_context(dq
);
28 test_ptr("dispatch_queue_get_context", ctxt
, ctxt_magic
);
29 test_ptr_notnull("finalizer ran", dq
);
32 test_long("dispatch_queue_attr_set_finalizer", res
, 0);
34 dispatch_queue_t q
= dispatch_queue_create(NULL
, attr
);
35 test_ptr_notnull("dispatch_queue_new", q
);
37 dispatch_queue_set_context(q
, ctxt_magic
);
39 dispatch_release(attr
);