Ejemplo n.º 1
0
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!");
}
Ejemplo n.º 2
0
Archivo: epoll.c Proyecto: iYefeng/acl
static EPOLL_EVENT *epfd_alloc(void)
{
	EPOLL_EVENT *ee = acl_mycalloc(1, sizeof(EPOLL_EVENT));
	int  maxfd = acl_open_limit(0);

	if (maxfd <= 0) {
		acl_msg_fatal("%s(%d), %s: acl_open_limit error %s",
			__FILE__, __LINE__, __FUNCTION__, acl_last_serror());
	}

	++maxfd;
	ee->fds  = (EPOLL_CTX **) acl_mymalloc(maxfd * sizeof(EPOLL_CTX *));
	ee->nfds = maxfd;

	return ee;
}
Ejemplo n.º 3
0
static int event_limit(int fdsize)
{
	const char *myname = "event_limit";

#ifdef ACL_UNIX
	if ((fdsize = acl_open_limit(fdsize)) < 0) {
		acl_msg_fatal("%s: unable to determine open file limit, err=%s",
			myname, acl_last_serror());
	}
#else
	if (fdsize == 0)
		fdsize = 1024;
#endif
	if ((unsigned) (fdsize) < FD_SETSIZE / 2 && fdsize < 256)
		acl_msg_warn("%s: could allocate space for only %d open files",
			myname, fdsize);

	acl_msg_info("%s: max fdsize: %d", myname, fdsize);

	return fdsize;
}