| 32 | } |
| 33 | |
| 34 | S32 internal_poll(KThread* thread, KPollData* data, U32 count, U32 timeout) { |
| 35 | KPollData* firstData=data; |
| 36 | |
| 37 | while (true) { |
| 38 | S32 result = 0; |
| 39 | BOXEDWINE_CRITICAL_SECTION_WITH_CONDITION(thread->pollCond); |
| 40 | bool interrupted = !thread->inSignal && thread->interrupted; |
| 41 | |
| 42 | if (interrupted) |
| 43 | thread->interrupted = false; |
| 44 | |
| 45 | data = firstData; |
| 46 | { |
| 47 | BOXEDWINE_CRITICAL_SECTION_WITH_MUTEX(thread->process->fdsMutex); |
| 48 | // gather locks before we check the data so that we don't miss one |
| 49 | for (U32 i = 0; i < count; i++) { |
| 50 | KFileDescriptor* fd; |
| 51 | |
| 52 | data->revents = 0; |
| 53 | if (data->fd >= 0) { |
| 54 | fd = thread->process->getFileDescriptor_nolock(data->fd); |
| 55 | if (fd) { |
| 56 | // even if 0, we still don't want to remove it and should still respond to POLLERR and POLLHUP |
| 57 | fd->kobject->waitForEvents(thread->pollCond, data->events | K_POLLERR); |
| 58 | } else { |
| 59 | data->revents = K_POLLNVAL; |
| 60 | } |
| 61 | } |
| 62 | data++; |
| 63 | } |
| 64 | |
| 65 | data = firstData; |
| 66 | for (U32 i = 0; i < count; i++) { |
| 67 | KFileDescriptor* fd = nullptr; |
| 68 | |
| 69 | if (data->fd >= 0) { |
| 70 | fd = thread->process->getFileDescriptor_nolock(data->fd); |
| 71 | } |
| 72 | if (fd) { |
| 73 | if (!fd->kobject->isOpen()) { |
| 74 | data->revents |= K_POLLHUP; |
| 75 | } |
| 76 | if ((data->events & K_POLLPRI) && fd->kobject->isPriorityReadReady()) { |
| 77 | data->revents |= K_POLLPRI; |
| 78 | } |
| 79 | if ((data->events & K_POLLIN) != 0 && fd->kobject->isReadReady()) { |
| 80 | data->revents |= K_POLLIN; |
| 81 | } |
| 82 | if ((data->events & K_POLLOUT) != 0 && fd->kobject->isWriteReady()) { |
| 83 | data->revents |= K_POLLOUT; |
| 84 | } |
| 85 | if (data->revents != 0) { |
| 86 | result++; |
| 87 | } |
| 88 | } |
| 89 | data++; |
| 90 | } |
| 91 | } |
no test coverage detected