fork: properly set up child process
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
ec4e9fc27d
commit
b926d50365
6 changed files with 73 additions and 25 deletions
|
|
@ -71,6 +71,13 @@ static int copy_parent(struct proc *new, struct proc *parent)
|
|||
|
||||
spinlock_release(&parent->mem_lock);
|
||||
|
||||
if (parent->fd_array_size) {
|
||||
spinlock_acquire(&parent->fd_lock);
|
||||
new->fd_array_size = parent->fd_array_size;
|
||||
new->fdt = kalloc(new->fd_array_size * sizeof(struct file), ALLOC_KERN);
|
||||
spinlock_release(&parent->fd_lock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,31 +9,56 @@ static struct {
|
|||
struct thread *head;
|
||||
struct thread *tail;
|
||||
spinlock_t lock;
|
||||
} _run_queue;
|
||||
} sched_queue;
|
||||
|
||||
void sched_add_thread(struct thread *t)
|
||||
{
|
||||
spinlock_acquire(&_run_queue.lock);
|
||||
spinlock_acquire(&sched_queue.lock);
|
||||
t->next = NULL;
|
||||
if (_run_queue.tail)
|
||||
_run_queue.tail->next = t;
|
||||
_run_queue.tail = t;
|
||||
if (!_run_queue.head)
|
||||
_run_queue.head = t;
|
||||
spinlock_release(&_run_queue.lock);
|
||||
if (sched_queue.tail)
|
||||
sched_queue.tail->next = t;
|
||||
sched_queue.tail = t;
|
||||
if (!sched_queue.head)
|
||||
sched_queue.head = t;
|
||||
spinlock_release(&sched_queue.lock);
|
||||
}
|
||||
|
||||
void sched_purge_proc(struct proc *proc)
|
||||
{
|
||||
spinlock_acquire(&sched_queue.lock);
|
||||
struct thread *t = sched_queue.head;
|
||||
struct thread *p = NULL;
|
||||
while (t) {
|
||||
if (t->proc == proc) {
|
||||
if (p)
|
||||
p->next = t->next;
|
||||
else
|
||||
sched_queue.head = t->next;
|
||||
|
||||
if (!t->next)
|
||||
sched_queue.tail = p;
|
||||
|
||||
t->next = NULL;
|
||||
|
||||
} else {
|
||||
p = t;
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
spinlock_release(&sched_queue.lock);
|
||||
}
|
||||
|
||||
static struct thread *dequeue_thread()
|
||||
{
|
||||
spinlock_acquire(&_run_queue.lock);
|
||||
struct thread *t = _run_queue.head;
|
||||
spinlock_acquire(&sched_queue.lock);
|
||||
struct thread *t = sched_queue.head;
|
||||
if (t) {
|
||||
_run_queue.head = t->next;
|
||||
if (!_run_queue.head)
|
||||
_run_queue.tail = NULL;
|
||||
sched_queue.head = t->next;
|
||||
if (!sched_queue.head)
|
||||
sched_queue.tail = NULL;
|
||||
t->next = NULL;
|
||||
}
|
||||
spinlock_release(&_run_queue.lock);
|
||||
spinlock_release(&sched_queue.lock);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue