void fiber_io_check(void) { if (__thread_fiber != NULL) { if (__thread_fiber->ev_fiber == NULL) { __thread_fiber->ev_fiber = acl_fiber_create( fiber_io_loop, __thread_fiber->event, STACK_SIZE); __thread_fiber->io_count = 0; __thread_fiber->nsleeping = 0; __thread_fiber->io_stop = 0; ring_init(&__thread_fiber->ev_timer); } return; } if (pthread_once(&__once_control, thread_init) != 0) { msg_fatal("%s(%d), %s: pthread_once error %s", __FILE__, __LINE__, __FUNCTION__, last_serror()); } var_maxfd = open_limit(0); if (var_maxfd <= 0) { var_maxfd = MAXFD; } __thread_fiber = (FIBER_TLS *) malloc(sizeof(FIBER_TLS)); __thread_fiber->event = event_create(var_maxfd); __thread_fiber->ev_fiber = acl_fiber_create(fiber_io_loop, __thread_fiber->event, STACK_SIZE); __thread_fiber->io_count = 0; __thread_fiber->nsleeping = 0; __thread_fiber->io_stop = 0; ring_init(&__thread_fiber->ev_timer); #ifdef SYS_WIN __thread_fiber->events = htable_create(var_maxfd); #else __thread_fiber->events = (FILE_EVENT **) calloc(var_maxfd, sizeof(FILE_EVENT*)); #endif if (__pthread_self() == main_thread_self()) { __main_fiber = __thread_fiber; atexit(fiber_io_main_free); } else if (pthread_setspecific(__fiber_key, __thread_fiber) != 0) { msg_fatal("pthread_setspecific error!"); } }
void fiber_io_check(void) { if (__thread_fiber != NULL) return; acl_assert(acl_pthread_once(&__once_control, thread_init) == 0); __maxfd = acl_open_limit(0); if (__maxfd <= 0) __maxfd = MAXFD; __thread_fiber = (FIBER_TLS *) acl_mymalloc(sizeof(FIBER_TLS)); __thread_fiber->event = event_create(__maxfd); __thread_fiber->io_fibers = (ACL_FIBER **) acl_mycalloc(__maxfd, sizeof(ACL_FIBER *)); __thread_fiber->ev_fiber = acl_fiber_create(fiber_io_loop, __thread_fiber->event, STACK_SIZE); __thread_fiber->io_count = 0; __thread_fiber->nsleeping = 0; __thread_fiber->io_stop = 0; acl_ring_init(&__thread_fiber->ev_timer); if ((unsigned long) acl_pthread_self() == acl_main_thread_self()) { __main_fiber = __thread_fiber; atexit(fiber_io_main_free); } else if (acl_pthread_setspecific(__fiber_key, __thread_fiber) != 0) acl_msg_fatal("acl_pthread_setspecific error!"); }
int main(int argc, char *argv[]) { int ch, i, nsenders = 1, nreceivers = 1, nbuf = 10; ACL_CHANNEL *chan; while ((ch = getopt(argc, argv, "hn:s:r:b:d:")) > 0) { switch (ch) { case 'h': usage(argv[0]); return 0; case 'n': __max = (unsigned long) atol(optarg); break; case 's': nsenders = atoi(optarg); break; case 'r': nreceivers = atoi(optarg); break; case 'b': nbuf = atoi(optarg); break; case 'd': __display = atoi(optarg); break; default: break; } } printf("max_count: %d\r\n", __max); chan = acl_channel_create(sizeof(unsigned long), nbuf); for (i = 0; i < nsenders; i++) acl_fiber_create(fiber_producer, chan, 320000); for (i = 0; i < nreceivers; i++) acl_fiber_create(fiber_consumer, chan, 320000); acl_fiber_schedule(); acl_channel_free(chan); return 0; }
void fiber::start(size_t stack_size /* = 64000 */) { if (f_ != NULL) acl_msg_fatal("%s(%d), %s: fiber-%u, already running!", __FILE__, __LINE__, __FUNCTION__, self()); acl_fiber_create(fiber_callback, this, stack_size); }
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++) acl_fiber_create(fiber_redis, &cluster, 327680); acl_fiber_schedule(); return 0; }
void fiber::start(size_t stack_size /* = 64000 */) { acl_fiber_create(fiber_callback, this, stack_size); }
void go_fiber::operator=(std::function<void()> fn) { fiber_ctx* ctx = new fiber_ctx(fn); acl_fiber_create(fiber_main, (void*) ctx, stack_size_); }
int main(int argc, char *argv[]) { int ch, conn_timeout = 0, rw_timeout = 0, nworkers = 10; acl::string addr("127.0.0.1:6379"), cmd("set"); while ((ch = getopt(argc, argv, "hs:n:c:r:t:w:a:")) > 0) { switch (ch) { case 'h': usage(argv[0]); return 0; case 'a': cmd = optarg; break; case 'w': nworkers = atoi(optarg); break; case 's': addr = optarg; break; case 'n': __oper_count = atoi(optarg); break; case 'c': __fibers_max = atoi(optarg); break; case 'r': rw_timeout = atoi(optarg); break; case 't': conn_timeout = atoi(optarg); break; default: break; } } acl::acl_cpp_init(); __redis_cluster.set(addr.c_str(), 0, conn_timeout, rw_timeout); //gettimeofday(&__begin, NULL); if (nworkers > __fibers_max) nworkers = __fibers_max; nworkers = __fibers_max; MYCHANS mychans; mychans.size = nworkers; mychans.off = 0; mychans.chans = new MYCHAN[nworkers]; for (int i = 0; i < nworkers; i++) { mychans.chans[i].chan = acl_channel_create(sizeof(void*), 1000); mychans.chans[i].cmd = cmd; } __workers = new ACL_FIBER*[nworkers + 1]; for (int i = 0; i < nworkers; i++) __workers[i] = acl_fiber_create(fiber_worker, &mychans.chans[i], 32000); __workers[nworkers] = NULL; __fibers_count = nworkers; for (int i = 0; i < __fibers_max; i++) (void) acl_fiber_create(fiber_result, &mychans, 32000); __chan_exit = acl_channel_create(sizeof(unsigned long), 1000); acl_fiber_create(fiber_wait, __chan_exit, 32000); acl_fiber_schedule(); for (int i = 0; i < nworkers; i++) acl_channel_free(mychans.chans[i].chan); delete [] mychans.chans; acl_channel_free(__chan_exit); delete [] __workers; return 0; }