Esempio n. 1
0
int main()
{
    fiber_manager_init(NUM_THREADS);

    fiber_rwlock_init(&mutex);
    fiber_barrier_init(&barrier, NUM_FIBERS);

    fiber_t* fibers[NUM_FIBERS];
    int i;
    for(i = 0; i < NUM_FIBERS; ++i) {
        fibers[i] = fiber_create(20000, &run_function, NULL);
    }

    for(i = 0; i < NUM_FIBERS; ++i) {
        fiber_join(fibers[i], NULL);
    }

    fiber_barrier_destroy(&barrier);
    fiber_rwlock_destroy(&mutex);

    printf("try_rd %d try_wr %d count_rd %d count_wr %d\n", try_rd, try_wr, count_rd, count_wr);

    fiber_manager_print_stats();
    return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	acl::string addr("127.0.0.1:9001");
	int  ch;

	while ((ch = getopt(argc, argv, "hs:r:")) > 0)
	{
		switch (ch)
		{
		case 'h':
			usage(argv[0]);
			return 0;
		case 's':
			addr = optarg;
			break;
		case 'r':
			__rw_timeout = atoi(optarg);
			break;
		default:
			break;
		}
	}

	acl::acl_cpp_init();
	acl::log::stdout_open(true);

	fiber_create(fiber_accept, addr.c_str(), STACK_SIZE);

	fiber_schedule();
}
Esempio n. 3
0
static void fiber_accept(FIBER *, void *ctx)
{
	const char* addr = (const char* ) ctx;
	acl::server_socket server;

	if (server.open(addr) == false)
	{
		printf("open %s error\r\n", addr);
		exit (1);
	}
	else
		printf("open %s ok\r\n", addr);

	while (true)
	{
		acl::socket_stream* client = server.accept();
		if (client == NULL)
		{
			printf("accept failed: %s\r\n", acl::last_serror());
			break;
		}

		client->set_rw_timeout(__rw_timeout);
		printf("accept one: %d\r\n", client->sock_handle());
		fiber_create(http_server, client, STACK_SIZE);
	}

	exit (0);
}
Esempio n. 4
0
int
flexsc_fiber(void *(*__fn)(void *arg), void *arg, int detached, unsigned int *fidp) {
    flexsc_assert(flexsc_enabled() && __this != NULL);
    struct fiber_struct *fiber;
    int ret;
    if ((ret = fiber_create(NULL, &fiber, detached, __fn, arg)) == 0) {
        if (fidp != NULL) {
            *fidp = fiber_fid(fiber);
        }
    }
    return ret;
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	int   ch, i, conn_timeout = 2, rw_timeout = 2;
	acl::string addr("127.0.0.1:6379");

	while ((ch = getopt(argc, argv, "hs:n:c:r:t:")) > 0) {
		switch (ch) {
		case 'h':
			usage(argv[0]);
			return 0;
		case 's':
			addr = optarg;
			break;
		case 'n':
			__oper_count = atoi(optarg);
			break;
		case 'c':
			__fibers_count = atoi(optarg);
			__fibers_max = __fibers_count;
			break;
		case 'r':
			rw_timeout = atoi(optarg);
			break;
		case 't':
			conn_timeout = atoi(optarg);
			break;
		default:
			break;
		}
	}

	acl::acl_cpp_init();

	acl::redis_client_cluster cluster;
	cluster.set(addr.c_str(), 0, conn_timeout, rw_timeout);

	gettimeofday(&__begin, NULL);

	for (i = 0; i < __fibers_count; i++)
		fiber_create(fiber_redis, &cluster, 327680);

	fiber_schedule();

	return 0;
}
Esempio n. 6
0
File: main.c Progetto: fatzero/acl
int main(void)
{
	const char *addr = "0.0.0.0:8089";
	ACL_VSTREAM *sstream = acl_vstream_listen(addr, 128);

	fiber_init();
	if (sstream == NULL) {
		printf("acl_vstream_listen error %s\r\n", acl_last_serror());
		return 1;
	}

	acl_non_blocking(ACL_VSTREAM_SOCK(sstream), ACL_NON_BLOCKING);

	printf("%s: call fiber_creater\r\n", __FUNCTION__);
	fiber_create(fiber_accept, sstream, 32768);
	printf("call fiber_schedule\r\n");
	fiber_schedule();

	return 0;
}
Esempio n. 7
0
int main()
{
    fiber_manager_set_total_kernel_threads(NUM_THREADS);

    fiber_mutex_init(&mutex);

    fiber_t* fibers[NUM_FIBERS];
    int i;
    for(i = 0; i < NUM_FIBERS; ++i) {
        fibers[i] = fiber_create(20000, &run_function, NULL);
    }

    for(i = 0; i < NUM_FIBERS; ++i) {
        fiber_join(fibers[i]);
    }

    test_assert(counter == NUM_FIBERS * PER_FIBER_COUNT);

    return 0;
}