标签:res 设置 assign flags callback 源码分析 函数 bsp 优先级
初始化完event_base后,下面要初始化event,通过调用event_set()实现 。相关源码位于event.c
void event_set(struct event *ev, int fd, short events, void (*callback)(int, short, void *), void *arg) { /* Take the current base - caller needs to set the real base later */ ev->ev_base = current_base; //设置event属于当前base;current_base通过event_init()设置 ev->ev_callback = callback; //设置回调函数 ev->ev_arg = arg; //设置回调函数的3个参数 ev->ev_fd = fd; ev->ev_events = events; ev->ev_res = 0; ev->ev_flags = EVLIST_INIT; //设置event状态 ev->ev_ncalls = 0; ev->ev_pncalls = NULL; min_heap_elem_init(ev); //初始化event在小根堆中索引为-1 min_heap.h /* by default, we put new events into the middle priority */ if(current_base) ev->ev_pri = current_base->nactivequeues/2; //设置event优先级 }
int event_base_set(struct event_base *base, struct event *ev) { /* Only innocent events may be assigned to a different base */ if (ev->ev_flags != EVLIST_INIT) //只能对新建的event设置其所属event_base return (-1); ev->ev_base = base; //设置所属event_base ev->ev_pri = base->nactivequeues/2; //设置优先级 return (0); }
int event_priority_set(struct event *ev, int pri) { if (ev->ev_flags & EVLIST_ACTIVE) //不能对活跃的event设置优先级 return (-1); if (pri < 0 || pri >= ev->ev_base->nactivequeues) return (-1); ev->ev_pri = pri; //设置优先级 return (0); }
标签:res 设置 assign flags callback 源码分析 函数 bsp 优先级
原文地址:http://www.cnblogs.com/zxiner/p/6920086.html