int main(void)
{
	test_start("Dispatch Suspend Timer");

	dispatch_queue_t main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

	__block int i = 0;
	__block int j = 0;

	dispatch_source_attr_t attr = dispatch_source_attr_create();
	test_ptr_notnull("dispatch_source_attr_create", attr);
	
	dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
		test_ptr_notnull("finalizer ran", ds);
		if (ds == tweedledum) test_stop();
	});
Пример #2
0
dispatch_source_attr_t
dispatch_source_attr_copy(dispatch_source_attr_t proto)
{
	dispatch_source_attr_t rval = NULL;

	if (proto && (rval = malloc(sizeof(struct dispatch_source_attr_s)))) {
		memcpy(rval, proto, sizeof(struct dispatch_source_attr_s));
#ifdef __BLOCKS__
		if (rval->finalizer_func == (void*)_dispatch_call_block_and_release2) {
			rval->finalizer_ctxt = Block_copy(rval->finalizer_ctxt);
		}
#endif
	} else if (!proto) {
		rval = dispatch_source_attr_create();
	}
	return rval;
}
Пример #3
0
int main(void)
{
    test_start("Dispatch Update Timer");

    dispatch_queue_t main_q = dispatch_get_main_queue();
    test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

    __block int i = 0;
    struct timeval start_time;

    gettimeofday(&start_time, NULL);
    dispatch_source_attr_t attr = dispatch_source_attr_create();
    dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
        struct timeval end_time;
        gettimeofday(&end_time, NULL);
        // Make sure we actually managed to adjust the interval
        // duration.  Seven one second ticks would blow past
        // this.
        test_long_less_than("total duration", end_time.tv_sec - start_time.tv_sec, 3);
        test_ptr_notnull("finalizer ran", ds);
        test_stop();
    });
int main(void)
{
	test_start("Dispatch Debug");

	dispatch_queue_t main_q = dispatch_get_main_queue();
	dispatch_debug(main_q, "dispatch_queue_t");
	
	dispatch_queue_t default_q = dispatch_get_concurrent_queue(0);
	dispatch_debug(default_q, "dispatch_queue_t");
	
	dispatch_source_attr_t attr = dispatch_source_attr_create();
	dispatch_debug(attr, "dispatch_source_attr_t");

	dispatch_source_t s = dispatch_source_timer_create(DISPATCH_TIMER_INTERVAL,
		1000000000ull, 0, attr, main_q, ^(dispatch_event_t ev __attribute__((unused))) {});
	dispatch_debug(s, "dispatch_source_t");

	dispatch_group_t g = dispatch_group_create();
	dispatch_debug(g, "dispatch_group_t");

	return 0;
}
int main(void)
{
	test_start("Dispatch Source Timer, bit 31");

	dispatch_queue_t main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());

	__block int i = 0;
	struct timeval start_time;

	gettimeofday(&start_time, NULL);
	dispatch_source_attr_t attr = dispatch_source_attr_create();
	dispatch_source_attr_set_finalizer(attr, ^(dispatch_source_t ds) {
		struct timeval end_time;
		gettimeofday(&end_time, NULL);
		test_ptr_notnull("finalizer ran", ds);
		// XXX: check, s/b 2.0799... seconds, which is <4 seconds
		// when it could end on a bad boundry.
		test_long_less_than("needs to finish faster than 4 seconds", end_time.tv_sec - start_time.tv_sec, 4);
		// And it has to take at least two seconds...
		test_long_less_than("can't finish faster than 2 seconds", 1, end_time.tv_sec - start_time.tv_sec);
		test_stop();
	});