git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: input device subsystem to resolve race condition on polling input
[lunaix-os.git]
/
lunaix-os
/
kernel
/
sched.c
diff --git
a/lunaix-os/kernel/sched.c
b/lunaix-os/kernel/sched.c
index d1ee39d21bc3424ce5399d2c60f71d53cea58dca..2274238061df347181a092c2008b560d2af46ddf 100644
(file)
--- a/
lunaix-os/kernel/sched.c
+++ b/
lunaix-os/kernel/sched.c
@@
-94,7
+94,7
@@
check_sleepers()
if (wtime && now >= wtime) {
pos->sleep.wakeup_time = 0;
if (wtime && now >= wtime) {
pos->sleep.wakeup_time = 0;
- pos->state = PS_
STOPPED
;
+ pos->state = PS_
READY
;
}
if (atime && now >= atime) {
}
if (atime && now >= atime) {
@@
-123,7
+123,7
@@
schedule()
int ptr = prev_ptr;
if (!(__current->state & ~PS_RUNNING)) {
int ptr = prev_ptr;
if (!(__current->state & ~PS_RUNNING)) {
- __current->state = PS_
STOPPED
;
+ __current->state = PS_
READY
;
}
check_sleepers();
}
check_sleepers();
@@
-133,7
+133,7
@@
redo:
do {
ptr = (ptr + 1) % sched_ctx.ptable_len;
next = &sched_ctx._procs[ptr];
do {
ptr = (ptr + 1) % sched_ctx.ptable_len;
next = &sched_ctx._procs[ptr];
- } while (next->state != PS_
STOPPED
&& ptr != prev_ptr);
+ } while (next->state != PS_
READY
&& ptr != prev_ptr);
sched_ctx.procs_index = ptr;
sched_ctx.procs_index = ptr;
@@
-145,6
+145,13
@@
redo:
run(next);
}
run(next);
}
+void
+sched_yieldk()
+{
+ cpu_enable_interrupt();
+ cpu_int(LUNAIX_SCHED);
+}
+
__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
{
if (!seconds) {
__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
{
if (!seconds) {
@@
-219,7
+226,6
@@
_wait(pid_t wpid, int* status, int options)
}
wpid = wpid ? wpid : -__current->pgid;
}
wpid = wpid ? wpid : -__current->pgid;
- cpu_enable_interrupt();
repeat:
llist_for_each(proc, n, &__current->children, siblings)
{
repeat:
llist_for_each(proc, n, &__current->children, siblings)
{
@@
-228,7
+234,7
@@
repeat:
status_flags |= PEXITTERM;
goto done;
}
status_flags |= PEXITTERM;
goto done;
}
- if (proc->state == PS_
STOPPED
&& (options & WUNTRACED)) {
+ if (proc->state == PS_
READY
&& (options & WUNTRACED)) {
status_flags |= PEXITSTOP;
goto done;
}
status_flags |= PEXITSTOP;
goto done;
}
@@
-238,11
+244,10
@@
repeat:
return 0;
}
// 放弃当前的运行机会
return 0;
}
// 放弃当前的运行机会
- sched_yield();
+ sched_yield
k
();
goto repeat;
done:
goto repeat;
done:
- cpu_disable_interrupt();
status_flags |= PEXITSIG * (proc->sig_inprogress != 0);
if (status) {
*status = proc->exit_code | status_flags;
status_flags |= PEXITSIG * (proc->sig_inprogress != 0);
if (status) {
*status = proc->exit_code | status_flags;
@@
-275,10
+280,11
@@
alloc_process()
proc->pgid = proc->pid;
proc->fdtable = vzalloc(sizeof(struct v_fdtable));
proc->pgid = proc->pid;
proc->fdtable = vzalloc(sizeof(struct v_fdtable));
- llist_init_head(&proc->mm.regions);
+ llist_init_head(&proc->mm.regions
.head
);
llist_init_head(&proc->children);
llist_init_head(&proc->grp_member);
llist_init_head(&proc->sleep.sleepers);
llist_init_head(&proc->children);
llist_init_head(&proc->grp_member);
llist_init_head(&proc->sleep.sleepers);
+ waitq_init(&proc->waitqueue);
return proc;
}
return proc;
}
@@
-300,7
+306,7
@@
commit_process(struct proc_info* process)
llist_append(&process->parent->children, &process->siblings);
llist_append(&process->parent->children, &process->siblings);
- process->state = PS_
STOPPED
;
+ process->state = PS_
READY
;
}
// from <kernel/process.c>
}
// from <kernel/process.c>
@@
-319,10
+325,18
@@
destroy_process(pid_t pid)
proc->state = PS_DESTROY;
llist_delete(&proc->siblings);
proc->state = PS_DESTROY;
llist_delete(&proc->siblings);
+ for (size_t i = 0; i < VFS_MAX_FD; i++) {
+ struct v_fd* fd = proc->fdtable->fds[i];
+ if (fd)
+ vfs_close(fd->file);
+ }
+
+ vfree(proc->fdtable);
+
struct mm_region *pos, *n;
llist_for_each(pos, n, &proc->mm.regions.head, head)
{
struct mm_region *pos, *n;
llist_for_each(pos, n, &proc->mm.regions.head, head)
{
-
lx
free(pos);
+
v
free(pos);
}
vmm_mount_pd(PD_MOUNT_1, proc->page_table);
}
vmm_mount_pd(PD_MOUNT_1, proc->page_table);