关于modifyEvent线程安全问题
hankai17 opened this issue · 3 comments
hankai17 commented
最近又读了作者的网络库 感觉非常精简 这里有个疑问
ZLToolKit/src/Poller/EventPoller.cpp
Line 164 in 5b30d6d
在EventPoller.cpp中观察到
int EventPoller::modifyEvent(int fd, int event) {
TimeTicker();
#if defined(HAS_EPOLL)
struct epoll_event ev = {0};
ev.events = toEpoll(event);
ev.data.fd = fd;
return epoll_ctl(_epoll_fd, EPOLL_CTL_MOD, fd, &ev);
我们知道 EventPoller 的接口设计是线程安全的
为何modifyEvent不像addEvent/delEvent里面那样有个类似于“异步调度或称为加锁(isCurrentThread)”的动作
也就是说 跨线程调用modifyEvent为何不需isCurrentThread判断?
xia-chu commented
因为epoll_ctl就是线程安全的
hankai17 commented
因为epoll_ctl就是线程安全的
明白 那么addEvent/delEvent里面是不是无需isCurrentThread判断?
hankai17 commented
明白 是为了确保_event_map容器线程安全