Finished Process_Wait implementation
This commit is contained in:
parent
9c4761b5f3
commit
ccebc2fe60
@ -61,6 +61,7 @@ typedef struct Process {
|
||||
TAILQ_ENTRY(Process) processList;
|
||||
uint64_t refCount;
|
||||
char title[PROCESS_TITLE_LENGTH];
|
||||
uint64_t exitCode;
|
||||
// Process
|
||||
Process *parent;
|
||||
TAILQ_ENTRY(Process) siblingList;
|
||||
@ -85,7 +86,7 @@ Process *Process_Create(Process *parent, const char *title);
|
||||
Process *Process_Lookup(uint64_t pid);
|
||||
void Process_Retain(Process *proc);
|
||||
void Process_Release(Process *proc);
|
||||
uint64_t Process_Wait(Process *proc);
|
||||
uint64_t Process_Wait(Process *proc, uint64_t pid);
|
||||
|
||||
// Thread functions
|
||||
Thread *Thread_Create(Process *proc);
|
||||
|
@ -44,6 +44,9 @@ Syscall_Exit(uint64_t status)
|
||||
|
||||
// Wait for all threads to exit
|
||||
|
||||
// Write exit code
|
||||
cur->proc->exitCode = status;
|
||||
|
||||
// Exit this thread
|
||||
Sched_SetZombie(cur);
|
||||
Thread_Release(cur);
|
||||
@ -125,7 +128,7 @@ Syscall_Wait(uint64_t pid)
|
||||
uint64_t status;
|
||||
Thread *cur = Sched_Current();
|
||||
|
||||
status = Process_Wait(cur->proc);
|
||||
status = Process_Wait(cur->proc, pid);
|
||||
Thread_Release(cur);
|
||||
|
||||
return status;
|
||||
|
@ -177,25 +177,41 @@ Process_Release(Process *proc)
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Process_Wait(Process *proc)
|
||||
Process_Wait(Process *proc, uint64_t pid)
|
||||
{
|
||||
Thread *thr;
|
||||
Thread *thr_temp;
|
||||
Process *p = NULL;
|
||||
uint64_t status;
|
||||
|
||||
// XXX: Implement pid checking
|
||||
Semaphore_Acquire(&proc->zombieProcSemaphore);
|
||||
// XXX: Forced exit check!
|
||||
// XXX: Need to verify pid exists!
|
||||
|
||||
Spinlock_Lock(&proc->lock);
|
||||
p = TAILQ_FIRST(&proc->zombieProc);
|
||||
TAILQ_REMOVE(&proc->zombieProc, p, siblingList);
|
||||
Spinlock_Unlock(&proc->lock);
|
||||
while (1) {
|
||||
Semaphore_Acquire(&proc->zombieProcSemaphore);
|
||||
// XXX: Forced exit check!
|
||||
|
||||
status = p->pid;
|
||||
Spinlock_Lock(&proc->lock);
|
||||
p = TAILQ_FIRST(&proc->zombieProc);
|
||||
if (pid == 0 || p->pid == pid) {
|
||||
TAILQ_REMOVE(&proc->zombieProc, p, siblingList);
|
||||
Spinlock_Unlock(&proc->lock);
|
||||
break;
|
||||
}
|
||||
Spinlock_Unlock(&proc->lock);
|
||||
|
||||
Semaphore_Release(&proc->zombieProcSemaphore);
|
||||
}
|
||||
|
||||
status = (p->pid << 16) | p->exitCode;
|
||||
|
||||
// Release threads
|
||||
TAILQ_FOREACH_SAFE(thr, &p->zombieQueue, schedQueue, thr_temp) {
|
||||
Thread_Dump(thr);
|
||||
Thread_Release(thr);
|
||||
}
|
||||
|
||||
// Release process
|
||||
Process_Release(p);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user