sys_read: implement different blocking mechanism
This commit is contained in:
parent
832420d8a7
commit
fba82790a9
3 changed files with 8 additions and 1 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
#define PROC_RUNNING 0
|
#define PROC_RUNNING 0
|
||||||
#define PROC_STOPPED 1
|
#define PROC_STOPPED 1
|
||||||
#define PROC_BLOCKED 2
|
#define PROC_BLOCKED 2
|
||||||
|
#define PROC_BLOCKED_SYSCALL 3
|
||||||
|
|
||||||
#define STDIN_FILENO 0
|
#define STDIN_FILENO 0
|
||||||
#define STDOUT_FILENO 1
|
#define STDOUT_FILENO 1
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ void schedule()
|
||||||
spinlock_acquire(&proc->lock);
|
spinlock_acquire(&proc->lock);
|
||||||
|
|
||||||
switch (proc->state) {
|
switch (proc->state) {
|
||||||
|
case PROC_BLOCKED_SYSCALL:
|
||||||
case PROC_STOPPED:
|
case PROC_STOPPED:
|
||||||
proc->state = PROC_RUNNING;
|
proc->state = PROC_RUNNING;
|
||||||
spinlock_release(&proc->lock);
|
spinlock_release(&proc->lock);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,12 @@ ssize_t sys_read(int fd, void *buf, size_t count)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
ret = vfs_read(file, tmp_buf, fdesc->pos, count);
|
while ((ret = vfs_read(file, tmp_buf, fdesc->pos, count)) == -EAGAIN) {
|
||||||
|
proc->state = PROC_BLOCKED_SYSCALL;
|
||||||
|
schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
proc->state = PROC_RUNNING;
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
memcpy(buf, tmp_buf, count);
|
memcpy(buf, tmp_buf, count);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue