예제 #1
0
int
main(int argc, char* argv[])
{
	// interval is 1/10th of a second
	uint64_t interval = NSEC_PER_SEC / 10;
	// for 25 seconds
	struct timeval now_tv;
	struct timespec now_ts;

	interval_d = (double)interval / (double)NSEC_PER_SEC;
	target = (unsigned int)(25 / interval_d);

	test_start("Timer drift test");

	timeBeginPeriod(1);

	timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
	test_ptr_notnull("DISPATCH_SOURCE_TYPE_TIMER", timer);
	
	dispatch_source_set_event_handler_f(timer, timer_handler);
	
	gettimeofday(&now_tv, NULL);
	now_ts.tv_sec = now_tv.tv_sec;
	now_ts.tv_nsec = now_tv.tv_usec * NSEC_PER_USEC;

	dispatch_source_set_timer(timer, dispatch_walltime(&now_ts, interval), interval, 0);

	dispatch_resume(as_do(timer));

	dispatch_main();
	return 0;
}
예제 #2
0
int
main()
{
	dispatch_queue_t q[PRIORITIES];
	int i;

#if USE_SET_TARGET_QUEUE
	test_start("Dispatch Priority (Set Target Queue)");
	for(i = 0; i < PRIORITIES; i++) {
		q[i] = dispatch_queue_create(labels[i], NULL);
		test_ptr_notnull("q[i]", q[i]);
		assert(q[i]);
		dispatch_set_target_queue(as_do(q[i]), dispatch_get_global_queue(priorities[i], 0));
		dispatch_queue_set_width(q[i], DISPATCH_QUEUE_WIDTH_MAX_LOGICAL_CPUS); 
	}
#else
	test_start("Dispatch Priority");
	for(i = 0; i < PRIORITIES; i++) {
		q[i] = dispatch_get_global_queue(priorities[i], 0);
	}
#endif
	
	for(i = 0; i < PRIORITIES; i++) {
		submit_work(q[i], &counts[i].count);
	}

	dispatch_main();
}
예제 #3
0
int
main(void)
{
    test_start("Dispatch After");

    dispatch_async_f(dispatch_get_main_queue(), NULL, func_outer);
    dispatch_main();
}
예제 #4
0
int main(void) {
	dispatch_queue_t q = dispatch_get_main_queue();
	test_start("Dispatch (Public) API");
	test_ptr_notnull("dispatch_get_main_queue", q);

	dispatch_async_f(dispatch_get_main_queue(), NULL, work);
	dispatch_main();
}
예제 #5
0
        bool operator()(Component const& component) const
        {
            typedef typename traits::container_value<Attr>::type lhs;
            typedef typename traits::attribute_of<
                Component, context_type, iterator_type>::type
            rhs_attribute;

            return dispatch_main(component
              , has_same_elements<lhs, rhs_attribute>());
        }
        bool operator()(Component const& component) const
        {
            typedef typename traits::container_value<Attr>::type rhs;
            typedef typename traits::attribute_of<
                Component, context_type>::type lhs_attribute;

            // false means everything went ok
            return dispatch_main(component
              , has_same_elements<rhs, lhs_attribute>());
        }
예제 #7
0
void dispatch_memory_use() {
	MU_BEGIN_TEST(dispatch_memory_use);

	do_test();

	dispatch_main();

	MU_FAIL("Should never reach this");
	MU_END_TEST
}
예제 #8
0
void dispatch_after_function()
{
    MU_BEGIN_TEST(dispatch_after);

    dispatch_async_f(dispatch_get_main_queue(),NULL,dispatch_start);

    dispatch_main();
    MU_FAIL("Should never reach this");
    MU_END_TEST;
}
예제 #9
0
void dispatch_starfish() {
	MU_BEGIN_TEST(dispatch_starfish);

	do_test();

	dispatch_main();

	MU_FAIL("Should never reach this");
	MU_END_TEST
}
예제 #10
0
int main(int argc, const char *argv[]) {
#ifdef _WIN32
    WSADATA wsadata;
    WSAStartup(MAKEWORD(2, 2), &wsadata);
#endif
    ldp_connection_t *conn = ldp_connection(events, NULL);
    const char *host = argc > 1 ? argv[1] : "host";
    const char *port = argc > 2 ? argv[2] : "8194";
    ldp_connection_connect(conn, host, port);
    dispatch_main();
}
extern "C" void
        dispatch_after_lambda(void)
{
    MU_BEGIN_TEST(dispatch_after_lambda);

    dispatch_async(dispatch_get_main_queue(), [=]{
		dispatch_time_t time_a_min = dispatch_time(0,  5.5*NSEC_PER_SEC);
        dispatch_time_t time_a     = dispatch_time(0,  6.0*NSEC_PER_SEC);
		dispatch_time_t time_a_max = dispatch_time(0,  6.5*NSEC_PER_SEC);
		dispatch_time_t time_a_start = dispatch_time(0,0);
        dispatch_after(time_a, dispatch_get_current_queue(), [=]{
			dispatch_time_t now_a = dispatch_time(0, 0);
			MU_MESSAGE("must finish between 5.5s and 6.5s: %f",(now_a-time_a_start)/(float)NSEC_PER_SEC);
			MU_ASSERT_TRUE(0<=(now_a - time_a_min));
			MU_ASSERT_TRUE(0<=(time_a_max - now_a));

			dispatch_time_t time_b_min = dispatch_time(0,  1.5*NSEC_PER_SEC);
			dispatch_time_t time_b     = dispatch_time(0,    2*NSEC_PER_SEC);
			dispatch_time_t time_b_max = dispatch_time(0,  2.5*NSEC_PER_SEC);
			dispatch_time_t time_b_start = dispatch_time(0,0);
            dispatch_after(time_b, dispatch_get_current_queue(), [=]{
				dispatch_time_t now_b = dispatch_time(0, 0);
				MU_MESSAGE("must finish between 1.5s and 2.5s: %f",(now_b-time_b_start)/(float)NSEC_PER_SEC);
				MU_ASSERT_TRUE(0<=(now_b - time_b_min));
				MU_ASSERT_TRUE(0<=(time_b_max - now_b));

#if 1 // FIXME: Nesting three lambdas seems to be broken...
				dispatch_time_t time_c_min = dispatch_time(0,  0*NSEC_PER_SEC);
				dispatch_time_t time_c     = dispatch_time(0,  0*NSEC_PER_SEC);
				dispatch_time_t time_c_max = dispatch_time(0,  .5*NSEC_PER_SEC);                
				dispatch_time_t time_c_start = dispatch_time(0, 0);
                dispatch_after(time_c, dispatch_get_current_queue(), [=]{
					dispatch_time_t now_c = dispatch_time(0, 0);
					MU_MESSAGE("must finish between 0s and .5s:  %f",(now_c-time_c_start)/(float)NSEC_PER_SEC);
					MU_ASSERT_TRUE(0<=(now_c - time_c_min));
					MU_ASSERT_TRUE(0<=(time_c_max - now_c));

					dispatch_async_f(dispatch_get_current_queue(), NULL, done);
				});
#else
                dispatch_async_f(dispatch_get_current_queue(), NULL, done);
#endif
			});
		});
	});

	dispatch_main();
	MU_FAIL("Should never reach this");
	MU_END_TEST;
}
        bool operator()(Component const& component) const
        {
            typedef typename traits::container_value<Attr>::type rhs;
            typedef typename traits::attribute_of<
                Component, context_type>::type lhs_attribute;

            typedef mpl::and_<
                has_same_elements<rhs, lhs_attribute>
              , traits::handles_container<Component, Attr, context_type>
            > predicate;

            // false means everything went ok
            return dispatch_main(component, predicate());
        }
예제 #13
0
int
main(void)
{
    test_start("Dispatch Reader/Writer Queues");

    dq = dispatch_queue_create("com.apple.libdispatch.test_readsync", NULL);
    assert(dq);

    dispatch_queue_set_width(dq, LONG_MAX);

    dispatch_apply_f(LAPS, dispatch_get_global_queue(0, 0), NULL, apply_fn);

    dispatch_release(as_do(dq));

    dispatch_main();
}
예제 #14
0
void dispatch_cascade() {
	int i;

	MU_BEGIN_TEST(dispatch_cascade);
	
	for (i = 0; i < QUEUES; ++i) {
		queues[i] = dispatch_queue_create(NULL, NULL);
	}

	for (i = 0; i < BLOCKS; ++i) {
		cascade(&indices[i].index);
	}

	dispatch_main();

	MU_FAIL("Should never reach this");
	MU_END_TEST;
}
예제 #15
0
void dispatch_group_function() {
	long res;
	dispatch_group_t group;

	MU_BEGIN_TEST(dispatch_group_function);

	group = create_group(100, 0);
	MU_ASSERT_NOT_NULL(group);

	dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
	
	// should be OK to re-use a group
	dispatch_group_async_f(group, dispatch_get_global_queue(0, 0), 0, foo);
	dispatch_group_wait(group, DISPATCH_TIME_FOREVER);

	dispatch_release(group);
	group = NULL;
	
	group = create_group(3, 7);
	MU_ASSERT_NOT_NULL(group);

	res = dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, 5ull * NSEC_PER_SEC));
    MU_ASSERT_EQUAL(!res, 0);

	// retry after timeout (this time succeed)
	res = dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, 5ull * NSEC_PER_SEC));
    MU_ASSERT_EQUAL(res, 0);

	dispatch_release(group);
	group = NULL;

	group = create_group(100, 0);
	MU_ASSERT_NOT_NULL(group);

	dispatch_group_notify_f(group, dispatch_get_main_queue(), 0, group_notify);
	
	dispatch_release(group);
	group = NULL;

	dispatch_main();

	MU_FAIL("Should never reach this");
	MU_END_TEST
}
예제 #16
0
void dispatch_api() {
    dispatch_queue_t q = NULL;

	MU_BEGIN_TEST(dispatch_api);

    q = dispatch_get_main_queue();
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_main_queue",q);
    dispatch_async_f(q, NULL, pass);

	q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q);
	q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0);
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q);
	q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q);

    dispatch_main();

	MU_END_TEST;
}
예제 #17
0
int
main(void)
{
	dispatch_queue_t main_q;

	test_start("Dispatch Update Timer");

	main_q = dispatch_get_main_queue();
	test_ptr("dispatch_get_main_queue", main_q, dispatch_get_current_queue());
	
	timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, main_q);
	dispatch_source_set_timer(timer, 1000000000ull, 0, 0);
	dispatch_source_set_cancel_handler_f(timer, cancel_handler);
	dispatch_source_set_event_handler_f(timer, event_handler);
	test_ptr_notnull("dispatch_source_timer_create", timer);

	gettimeofday(&start_time, NULL);
	dispatch_resume(as_do(timer));

	dispatch_main();
}
예제 #18
0
int
main(void) {
	test_start("Dispatch Queue Finalizer");

#ifdef __LP64__
	ctxt_magic = (void*)((uintptr_t)arc4random() << 32 | arc4random());
#else
	ctxt_magic = (void*)arc4random();
#endif

	dispatch_queue_t q = dispatch_queue_create(NULL, NULL);
	test_ptr_notnull("dispatch_queue_new", q);

	dispatch_set_context(q, ctxt_magic);

	dispatch_set_finalizer_f(q, finalizer);
	
	dispatch_release(q);

	dispatch_main();
	
	return 0;
}
예제 #19
0
int main(int argc, char **argv)
{
    DNSXErrorType err;

    // Default i/p intf is lo0 and o/p intf is primary interface
    IfIndex Ipintfs[MaxInputIf] =  {1, 0, 0, 0, 0};
    IfIndex Opintf = kDNSIfindexAny;

    // Extract program name from argv[0], which by convention contains the path to this executable
    const char *a0 = strrchr(argv[0], kFilePathSep) + 1; 
    if (a0 == (const char *)1)
        a0 = argv[0];

    // Must run as root
    if (0 != geteuid()) 
    {        
        fprintf(stderr, "%s MUST run as root!!\n", a0); 
        exit(-1); 
    }
    if ((sizeof(argv) == 8))
        printf("dnsctl running in 64-bit mode\n");
    else if ((sizeof(argv) == 4))
        printf("dnsctl running in 32-bit mode\n");

    // expects atleast one argument
    if (argc < 2)
        goto Usage;

    if ( !strcmp(argv[1], "-DP") || !strcmp(argv[1], "-dp") )
    {
        if (argc == 2)
        {
            printtimestamp();
            printf("Proceeding to Enable DNSProxy on mDNSResponder with Default Parameters\n");
            dispatch_queue_t my_Q = dispatch_queue_create("com.apple.dnsctl.callback_queue", NULL);
            err = DNSXEnableProxy(&ClientRef, kDNSProxyEnable, Ipintfs, Opintf, my_Q, dnsproxy_reply);
        }            
        else if (argc > 2)
        {
            argc--;
            argv++;
            if (!strcmp(argv[1], "-o"))
            {
                Opintf = if_nametoindex(argv[2]);
                if (!Opintf) 
                    Opintf = atoi(argv[2]);
                if (!Opintf) 
                { 
                    fprintf(stderr, "Could not parse o/p interface [%s]: Passing default primary \n", argv[2]); 
                    Opintf = kDNSIfindexAny;
                }
                argc -= 2;
                argv += 2;
            }
            if (argc > 2 && !strcmp(argv[1], "-i")) 
            {
                int i;
                argc--;
                argv++;
                for (i = 0; i < MaxInputIf && argc > 1; i++)
                {
                    Ipintfs[i] = if_nametoindex(argv[1]);
                    if (!Ipintfs[i])
                        Ipintfs[i] = atoi(argv[1]);  
                    if (!Ipintfs[i])
                    {
                        fprintf(stderr, "Could not parse i/p interface [%s]: Passing default lo0 \n", argv[2]); 
                        Ipintfs[i] = 1;
                    }
                    argc--;
                    argv++;
                }
            }  
            printtimestamp();
            printf("Proceeding to Enable DNSProxy on mDNSResponder \n");
            dispatch_queue_t my_Q = dispatch_queue_create("com.apple.dnsctl.callback_queue", NULL);
            err = DNSXEnableProxy(&ClientRef, kDNSProxyEnable, Ipintfs, Opintf, my_Q, dnsproxy_reply);                
        }
    }
    else
    {
        goto Usage;
    }

    dispatch_main(); 

Usage:
    print_usage(a0);
    return 0;
}
예제 #20
0
파일: gcd.c 프로젝트: JosephKu/MacRuby
static VALUE
rb_main_queue_run(VALUE self, SEL sel)
{
    dispatch_main();
    return Qnil; // never reached
}
예제 #21
0
int main(int argc, char* argv[]) {

	struct ttysize tsz;
	int res;

	res = ioctl(STDIN_FILENO, TIOCGWINSZ, &tsz);
	if (res == 0) {
		grid_x_size = tsz.ts_cols;
		grid_y_size = tsz.ts_lines;
	}

	int dispflag = 1;
	int ch;
	
	while ((ch = getopt(argc, argv, "x:y:q")) != -1) {
		char* endptr;
		switch (ch) {
			case 'x':
				grid_x_size = strtol(optarg, &endptr, 10);
				if (grid_x_size < 0 || (endptr && *endptr != 0)) {
					fprintf(stderr, "life: invalid x size\n");
					exit(1);
				}
				break;
			case 'y':
				grid_y_size = strtol(optarg, &endptr, 10);
				if (grid_y_size < 0 || (endptr && *endptr != 0)) {
					fprintf(stderr, "life: invalid y size\n");
					exit(1);
				}
				break;
			case 'q':
				dispflag = 0;
				break;
			case '?':
			default:
				fprintf(stderr, "usage: life [-q] [-x size] [-y size]\n");
				fprintf(stderr, "\t-x: grid x size (default is terminal columns)\n");
				fprintf(stderr, "\t-y: grid y size (default is terminal rows)\n");
				fprintf(stderr, "\t-q: suppress display output\n");
				exit(1);
		}
	}

	struct cell* grid = init_grid(grid_x_size, grid_y_size);

	if (dispflag) {
		init_display(grid);
		if (use_curses) {
			initscr(); cbreak(); noecho();
			nonl();
			intrflush(stdscr, FALSE);
			keypad(stdscr, TRUE);
		}
	}
	
	dispatch_main();

	if (dispflag && use_curses) {
		endwin();
	}
	
	return 0;
}
예제 #22
0
파일: base.cpp 프로젝트: digiverse/cool
void xdispatch::exec()
{
    dispatch_main();
}