| 58 | } |
| 59 | |
| 60 | void TIOService::TImpl::Run() { |
| 61 | TEvh& iEvh = Evh_.Get(I_.Fd()); |
| 62 | iEvh.Reset(new TInterrupterHandler(*this, I_)); |
| 63 | |
| 64 | TInterrupterKeeper ik(*this, iEvh); |
| 65 | Y_UNUSED(ik); |
| 66 | IPollerFace::TEvents evs; |
| 67 | AtomicSet(NeedCheckOpQueue_, 1); |
| 68 | TInstant deadline; |
| 69 | |
| 70 | while (Y_LIKELY(!Aborted_ && (AtomicGet(OutstandingWork_) || FdEventHandlersCnt_ > 1 || TimersOpCnt_ || AtomicGet(NeedCheckOpQueue_)))) { |
| 71 | //while |
| 72 | // expected work (external flag) |
| 73 | // or have event handlers (exclude interrupter) |
| 74 | // or have not completed timer operation |
| 75 | // or have any operation in queues |
| 76 | |
| 77 | AtomicIncrement(IsWaiting_); |
| 78 | if (!AtomicGet(NeedCheckOpQueue_)) { |
| 79 | P_->Wait(evs, deadline); |
| 80 | } |
| 81 | AtomicDecrement(IsWaiting_); |
| 82 | |
| 83 | if (evs.size()) { |
| 84 | for (IPollerFace::TEvents::const_iterator iev = evs.begin(); iev != evs.end() && !Aborted_; ++iev) { |
| 85 | const IPollerFace::TEvent& ev = *iev; |
| 86 | TEvh& evh = *(TEvh*)ev.Data; |
| 87 | |
| 88 | if (!evh) { |
| 89 | continue; //op. cancel (see ProcessOpQueue) can destroy evh |
| 90 | } |
| 91 | |
| 92 | int status = ev.Status; |
| 93 | if (ev.Status == EIO) { |
| 94 | int error = status; |
| 95 | if (GetSockOpt(evh->Fd(), SOL_SOCKET, SO_ERROR, error) == 0) { |
| 96 | status = error; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | OnFdEvent(evh, status, ev.Filter); //here handle fd events |
| 101 | //immediatly after handling events for one descriptor check op. queue |
| 102 | //often queue can contain another operation for this fd (next async read as sample) |
| 103 | //so we can optimize redundant epoll_ctl (or similar) calls |
| 104 | ProcessOpQueue(); |
| 105 | } |
| 106 | |
| 107 | evs.clear(); |
| 108 | } else { |
| 109 | ProcessOpQueue(); |
| 110 | } |
| 111 | |
| 112 | deadline = DeadlinesQueue_.NextDeadline(); //here handle timeouts/process timers |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | void TIOService::TImpl::Abort() { |
| 117 | class TAbortOperation: public TNoneOperation { |
nothing calls this directly
no test coverage detected