sched: add kernel API for blocking processes
This commit is contained in:
parent
3b1dc7e153
commit
5f00dac0ea
3 changed files with 44 additions and 0 deletions
|
|
@ -209,6 +209,12 @@ gate_syscall:
|
|||
movq %rax, 0(%rdi)
|
||||
call schedule
|
||||
|
||||
.global syscall_block
|
||||
syscall_block:
|
||||
cli
|
||||
save_context
|
||||
call schedule
|
||||
|
||||
/* void return_from_irq(struct procregs *regs, paddr_t cr3); */
|
||||
.global _return_to_user
|
||||
_return_to_user:
|
||||
|
|
|
|||
35
sched/proc.c
35
sched/proc.c
|
|
@ -3,6 +3,7 @@
|
|||
#include <kernel/proc.h>
|
||||
#include <kernel/rbtree.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <kernel/gdt.h>
|
||||
|
||||
#include <dev/apic.h>
|
||||
|
||||
|
|
@ -143,6 +144,40 @@ void schedule()
|
|||
}
|
||||
}
|
||||
|
||||
void proc_block(pid_t pid, bool in_kernel)
|
||||
{
|
||||
struct proc *proc = proc_find(pid);
|
||||
|
||||
if (proc) {
|
||||
spinlock_acquire(&proc->lock);
|
||||
proc->state = PROC_BLOCKED;
|
||||
|
||||
if (in_kernel) {
|
||||
proc->blocked_in_kernel = true;
|
||||
proc->regs.ss = GDT_SEGMENT_DATA_RING0;
|
||||
proc->regs.cs = GDT_SEGMENT_CODE_RING0;
|
||||
}
|
||||
|
||||
spinlock_release(&proc->lock);
|
||||
}
|
||||
}
|
||||
|
||||
void proc_unblock(pid_t pid)
|
||||
{
|
||||
struct proc *proc = proc_find(pid);
|
||||
|
||||
if (proc) {
|
||||
spinlock_acquire(&proc->lock);
|
||||
proc->state = PROC_BLOCKED;
|
||||
|
||||
proc->blocked_in_kernel = true;
|
||||
proc->regs.ss = GDT_SEGMENT_DATA_RING3 | 3;
|
||||
proc->regs.cs = GDT_SEGMENT_CODE_RING3 | 3;
|
||||
|
||||
spinlock_release(&proc->lock);
|
||||
}
|
||||
}
|
||||
|
||||
struct proc *proc_create()
|
||||
{
|
||||
struct proc *proc = slab_alloc(proc_slab);
|
||||
|
|
|
|||
Loading…
Reference in a new issue