MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / kselect

Function kselect

source/kernel/kpoll.cpp:160–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158
159
160U32 kselect(KThread* thread, U32 nfds, U32 readfds, U32 writefds, U32 errorfds, U32 timeout, bool timeoutIsTimeVal, U32 sigmask, bool time64) {
161 S32 result = 0;
162 int count = 0;
163 U32 pollCount = 0;
164 KMemory* memory = thread->memory;
165
166 if (timeout == 0)
167 timeout = 0x7FFFFFFF;
168 else {
169 // timeval, 2nd part is microseconds
170 // timespec, 2nd part is nanoseconds
171 if (time64) {
172 timeout = (U32)(memory->readq(timeout) * 1000 + memory->readd(timeout + 8) / (timeoutIsTimeVal?1000:1000000));
173 } else {
174 timeout = memory->readd(timeout) * 1000 + memory->readd(timeout + 4) / (timeoutIsTimeVal ? 1000 : 1000000);
175 }
176 if (timeout < NUMBER_OF_MILLIES_TO_SPIN_FOR_WAIT && nfds == 0) {
177 return KThread::currentThread()->sleep(timeout);
178 }
179 }
180
181 KPollData* pollData = new KPollData[nfds];
182
183 for (U32 i=0;i<nfds;) {
184 U32 readbits = 0;
185 U32 writebits = 0;
186 U32 errorbits = 0;
187
188 if (readfds!=0) {
189 readbits = memory->readb(readfds + i / 8);
190 }
191 if (writefds!=0) {
192 writebits = memory->readb(writefds + i / 8);
193 }
194 if (errorfds!=0) {
195 errorbits = memory->readb(errorfds + i / 8);
196 }
197 for (U32 b = 0; b < 8 && i < nfds; b++, i++) {
198 U32 mask = 1 << b;
199 U32 r = readbits & mask;
200 U32 w = writebits & mask;
201 U32 e = errorbits & mask;
202 if (r || w || e) {
203 U32 events = 0;
204 if (r)
205 events |= K_POLLIN;
206 if (w)
207 events |= K_POLLHUP|K_POLLOUT;
208 if (e)
209 events |= K_POLLERR;
210 pollData[pollCount].events = events;
211 pollData[pollCount].fd = i;
212 pollCount++;
213 }
214 }
215 }
216 if (sigmask) {
217 U32 mask = thread->memory->readd(sigmask);

Callers 3

syscall_newselectFunction · 0.85
syscall_pselect6Function · 0.85
syscall_pselect6_time64Function · 0.85

Calls 7

internal_pollFunction · 0.85
readqMethod · 0.80
memsetMethod · 0.80
readdMethod · 0.45
sleepMethod · 0.45
readbMethod · 0.45
writebMethod · 0.45

Tested by

no test coverage detected