- 论坛徽章:
- 4
|
本帖最后由 linux_c_py_php 于 2013-01-23 23:30 编辑
- class LF_Event_Handler : public Event_Handler {
- private:
- // This use of <Event_Handler> plays the
- // <ConcreteComponent> role in the Decorator
- // pattern, which is used to implement
- // the application-specific functionality.
- Event_Handler *concrete_event_handler_;
- // Instance of an <LF_Thread_Pool>.
- LF_Thread_Pool *thread_pool_;
- public:
- LF_Event_Handler (Event_Handler *eh,
- LF_Thread_Pool *tp)
- : concrete_event_handler_ (eh),
- thread_pool_ (tp) {}
- virtual int handle_event (HANDLE h, Event_Type et) {
- // Temporarily deactivate the handler in the
- // reactor to prevent race conditions.
- thread_pool_->deactivate_handle (h, et);
- // Promote a follower thread to become leader.
- thread_pool_->promote_new_leader ();
- // Dispatch application-specific event
- // processing code.
- concrete_event_handler_->handle_event (h, et);
- // Reactivate the handle in the reactor.
- thread_pool_->reactivate_handle (h, et);
- }
- };
复制代码 18页.
语境就是leader做I/O复用检测到某个fd的event, 然后先从fdset里去掉该fd, 然后让出leader, 然后handle_event处理这个fd发生的event, 最后reactivate_handle恢复这个fd的监听到fdset.
我注意到最后一步把fd重新加入fdset是无锁进行的, 此刻可能有另一个线程已经成为leader并处于epoll, 这样加入有可能吗? |
|