| 173 | } |
| 174 | |
| 175 | U32 KEPoll::wait(KThread* thread, U32 events, U32 maxevents, U32 timeout) { |
| 176 | S32 result = 0; |
| 177 | U32 pollCount=0; |
| 178 | KMemory* memory = thread->memory; |
| 179 | |
| 180 | thread->pollData.clear(); |
| 181 | for( const auto& n : this->data ) { |
| 182 | Data* next = n.value; |
| 183 | KPollData pollData; |
| 184 | |
| 185 | pollData.events = next->events; |
| 186 | pollData.fd = next->fd; |
| 187 | pollData.data = next->data; |
| 188 | thread->pollData.push_back(pollData); |
| 189 | pollCount++; |
| 190 | } |
| 191 | result = internal_poll(thread, thread->pollData.data(), pollCount, timeout); |
| 192 | if (result >= 0) { |
| 193 | result = 0; |
| 194 | for (KPollData& data : thread->pollData) { |
| 195 | if (data.revents!=0) { |
| 196 | memory->writed(events + result * 12, data.revents); |
| 197 | memory->writeq(events + result * 12 + 4, data.data); |
| 198 | result++; |
| 199 | if (result>=(S32)maxevents) { |
| 200 | kwarn("possible starvation in epoll, more events are ready than can be received."); |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | return result; |
| 207 | } |
no test coverage detected