转载请注明出处: http://blog.csdn.net/luotuo44/article/details/38512719
event_base允许用户对它里面的event设置优先级,这样可以使得有些更重要的event能够得到优先处理。
Libevent实现优先级功能的方法是:用一个激活队列数组来存放激活event。即数组的元素是一个激活队列,所以有多个激活队列。并且规定不同的队列有不同的优先级。
可以通过event_base_priority_init函数设置event_base的优先级个数,该函数实现如下:
//event.c文件
int
event_base_priority_init(struct event_base *base, int npriorities)
{
int i;
//由N_ACTIVE_CALLBACKS宏可以知道,本函数应该要在event_base_dispatch
//函数调用前调用。不然将无法设置。
if (N_ACTIVE_CALLBACKS(base) || npriorities < 1
|| npriorities >= EVENT_MAX_PRIORITIES)
return (-1);
//之前和现在要设置的优先级数是一样的。
if (npriorities =&#