mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
exit: fix deadlock
This commit is contained in:
+10
-7
@@ -8,7 +8,11 @@
|
|||||||
|
|
||||||
void syscall_exit(int status){
|
void syscall_exit(int status){
|
||||||
proc_t* proc = arch_getcls()->thread->proc;
|
proc_t* proc = arch_getcls()->thread->proc;
|
||||||
|
|
||||||
|
|
||||||
|
proc_t* init = sched_getinit();
|
||||||
|
|
||||||
|
spinlock_acquire(&init->lock);
|
||||||
spinlock_acquire(&proc->lock);
|
spinlock_acquire(&proc->lock);
|
||||||
|
|
||||||
// TODO make all other threads exit
|
// TODO make all other threads exit
|
||||||
@@ -26,25 +30,23 @@ void syscall_exit(int status){
|
|||||||
vfs_close(proc->root);
|
vfs_close(proc->root);
|
||||||
vfs_close(proc->cwd);
|
vfs_close(proc->cwd);
|
||||||
|
|
||||||
proc_t* init = sched_getinit();
|
|
||||||
|
|
||||||
spinlock_acquire(&init->lock);
|
|
||||||
|
|
||||||
proc_t* child = proc->child;
|
proc_t* child = proc->child;
|
||||||
proc_t* firstchild = child;
|
proc_t* firstchild = child;
|
||||||
|
|
||||||
while(child){
|
while(child){
|
||||||
spinlock_acquire(&child->lock);
|
spinlock_acquire(&child->lock);
|
||||||
child->parent = init;
|
child->parent = init;
|
||||||
|
proc_t* oldc = child;
|
||||||
|
proc_t* oldsibling = oldc->sibling;
|
||||||
if(!child->sibling){
|
if(!child->sibling){
|
||||||
child->sibling = init->child;
|
child->sibling = init->child;
|
||||||
init->child = firstchild;
|
init->child = firstchild;
|
||||||
}
|
}
|
||||||
spinlock_release(&child->lock);
|
|
||||||
child = child->sibling;
|
child = oldsibling;
|
||||||
|
spinlock_release(&oldc->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
spinlock_release(&init->lock);
|
|
||||||
event_signal(&proc->parent->childevent, true);
|
event_signal(&proc->parent->childevent, true);
|
||||||
|
|
||||||
// context and thread destruction will happen in the waitpid()
|
// context and thread destruction will happen in the waitpid()
|
||||||
@@ -55,6 +57,7 @@ void syscall_exit(int status){
|
|||||||
arch_interrupt_disable();
|
arch_interrupt_disable();
|
||||||
|
|
||||||
spinlock_release(&proc->lock);
|
spinlock_release(&proc->lock);
|
||||||
|
spinlock_release(&init->lock);
|
||||||
|
|
||||||
sched_dequeue();
|
sched_dequeue();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user