1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

Implement a basic way for read() to block.

FileHandle gets a hasDataAvailableForRead() getter.
If this returns true in sys$read(), the task will block(BlockedRead) + yield.
The fd blocked on is stored in Task::m_fdBlockedOnRead.
The scheduler then looks at the state of that fd during the unblock phase.

This makes "sh" restful. :^)

There's still some problem with the kernel not surviving the colonel task
getting scheduled. I need to figure that out and fix it.
This commit is contained in:
Andreas Kling 2018-10-25 13:07:59 +02:00
parent ba56f4afde
commit c6f2890d8e
18 changed files with 86 additions and 17 deletions

View file

@ -466,6 +466,14 @@ bool scheduleNewTask()
continue;
}
}
if (task->state() == Task::BlockedRead) {
ASSERT(task->m_fdBlockedOnRead != -1);
if (task->m_fileHandles[task->m_fdBlockedOnRead]->hasDataAvailableForRead()) {
task->unblock();
continue;
}
}
}
#if 0
@ -619,6 +627,13 @@ ssize_t Task::sys$read(int fd, void* outbuf, size_t nread)
#ifdef DEBUG_IO
kprintf("call read on handle=%p\n", handle);
#endif
if (handle->isBlocking()) {
if (!handle->hasDataAvailableForRead()) {
m_fdBlockedOnRead = fd;
block(BlockedRead);
yield();
}
}
nread = handle->read((byte*)outbuf, nread);
#ifdef DEBUG_IO
kprintf("Task::sys$read: nread=%u\n", nread);