libevent源码分析:event_add、event_del
event_add、event_del两个函数分别是使event生效和失效的,下面就来看一下两个函数的实现。 event_add 1 int 2 event_add(struct event *ev, const struct timeval *tv) 3 { 4 int res; 5 6 if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { 7 event_warnx("%s: event has no event_base set.", __func__); 8 return -1; 9 } 10 11 EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); 12 13 res = event_add_nolock_(ev, tv, 0); 14 15 EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); 16 17 return (res); 18 } 19 20 /* Implementation function to add an event. Works just like event_add, 21 * except: 1) it requires that we have the lock. 2) if tv_is_absolute is set, 22