[sheepdog] [PATCH v2 1/2] lib: prioritize events for epoll() and enhance event loop

Liu Yuan namei.unix at gmail.com
Fri Dec 21 18:41:20 CET 2012


On 12/22/2012 01:23 AM, Hitoshi Mitake wrote:
> +	nr = epoll_wait(efd, polled_events, nr_events, TICK * 1000);
>  	if (nr < 0) {
>  		if (errno == EINTR)
>  			return;
>  		eprintf("epoll_wait failed: %m\n");
>  		exit(1);
>  	} else if (nr) {
> +		if (prioritized)

simply if (nr_prioritized_events) is okay, then we can remove prioritized.

> +			qsort(polled_events, nr, sizeof(struct epoll_event),
> +				epoll_event_cmp);
> +
>  		for (i = 0; i < nr; i++) {
>  			struct event_info *ei;
> +			uint32_t e;
> +			enum event_ret ret;
> +
> +			ei = (struct event_info *)polled_events[i].data.ptr;
> +			e = polled_events[i].events;
> +
> +			ret = ei->handler(ei->fd, e, ei->data);
> +			switch (ret) {
> +			case EVENT_LOOP_NOP:
> +				break;
>  
> -			ei = (struct event_info *)events[i].data.ptr;
> -			ei->handler(ei->fd, events[i].events, ei->data);
> +			case EVENT_LOOP_RETRIEVE:
> +				goto retrieve;
> +
> +			case EVENT_LOOP_BREAK:
> +				goto end;
> +

No whitespace for case clause please.

> +			default:
> +				panic("invalid event_ret: %d\n", ret);
> +				break;
> +			}
>  		}
>  	}
> +

Thanks,
Yuan



More information about the sheepdog mailing list