From a1559a166494432e89a1a402645faf58df4211f3 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Mon, 19 Feb 2024 02:43:51 -0500 Subject: [PATCH] sched: unblock process after blocking read syscall --- sched/syscall.c | 12 +++++++++++- usr.bin/shtest/shtest.c | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sched/syscall.c b/sched/syscall.c index 5ae7516..815104a 100644 --- a/sched/syscall.c +++ b/sched/syscall.c @@ -41,7 +41,17 @@ ssize_t sys_read(int fd, void *buf, size_t count) if (tmp_buf == NULL) return -ENOMEM; - ssize_t ret = vfs_read(file, tmp_buf, fdesc->pos, count); + ssize_t ret; + bool blocked = false; + while ((ret = vfs_read(file, tmp_buf, fdesc->pos, count)) == -EAGAIN) { + blocked = true; + proc_block(getpid(), true); + yield(); + } + + if (blocked) + proc_unblock(getpid()); + if (ret > 0) memcpy(buf, tmp_buf, count); else diff --git a/usr.bin/shtest/shtest.c b/usr.bin/shtest/shtest.c index 058e99f..2caa411 100644 --- a/usr.bin/shtest/shtest.c +++ b/usr.bin/shtest/shtest.c @@ -22,6 +22,8 @@ void _start() if (fd < 0) exit(1); + write(fd, "shtest: simple userland shell test\n", 35); + promptfd(fd); char c;