From: John Hodge Date: Fri, 25 Sep 2009 03:13:31 +0000 (+0800) Subject: Fixed thread deletion when not explicitly killed. X-Git-Tag: rel0.06~519 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=cc4cb2c933b04f63a236735bbfc8a055c1bf5abd;p=tpg%2Facess2.git Fixed thread deletion when not explicitly killed. --- diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index 47200c62..ebfdbed3 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -65,19 +65,24 @@ void SyscallHandler(tSyscallRegs *Regs) ret = Threads_WaitTID(Regs->Arg1, (void*)Regs->Arg2); break; + // -- Get the physical address of a page case SYS_GETPHYS: ret = MM_GetPhysAddr(Regs->Arg1); break; + // -- Map an address case SYS_MAP: MM_Map(Regs->Arg1, Regs->Arg2); break; + // -- Allocate an address case SYS_ALLOCATE: ret = MM_Allocate(Regs->Arg1); break; + // -- Unmap an address case SYS_UNMAP: MM_Deallocate(Regs->Arg1); break; // -- Get Thread/Process IDs case SYS_GETTID: ret = Threads_GetTID(); break; case SYS_GETPID: ret = Threads_GetPID(); break; + // -- Get User/Group IDs case SYS_GETUID: ret = Threads_GetUID(); break; case SYS_GETGID: ret = Threads_GetGID(); break; diff --git a/Kernel/threads.c b/Kernel/threads.c index 1644b504..1ccac9f6 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -23,6 +23,7 @@ void Threads_SetName(char *NewName); void Threads_SetTickets(int Num); int Threads_WaitTID(int TID, int *status); tThread *Threads_GetThread(Uint TID); +void Threads_AddToDelete(tThread *Thread); tThread *Threads_int_GetPrev(tThread **List, tThread *Thread); void Threads_Exit(int TID, int Status); void Threads_Kill(tThread *Thread, int Status); @@ -164,10 +165,11 @@ int Threads_WaitTID(int TID, int *status) { case THREAD_STAT_ZOMBIE: t->Status = THREAD_STAT_DEAD; - *status = 0; + if(status) *status = 0; + Threads_AddToDelete( t ); break; default: - *status = -1; + if(status) *status = -1; break; } return ret; @@ -205,6 +207,22 @@ tThread *Threads_GetThread(Uint TID) return NULL; } +/** + * \fn void Threads_AddToDelete(tThread *Thread) + * \brief Adds a thread to the delete queue + */ +void Threads_AddToDelete(tThread *Thread) +{ + // Add to delete queue + if(gDeleteThreads) { + Thread->Next = gDeleteThreads; + gDeleteThreads = Thread; + } else { + Thread->Next = NULL; + gDeleteThreads = Thread; + } +} + /** * \fn tThread *Threads_int_GetPrev(tThread *List, tThread *Thread) * \brief Gets the previous entry in a thead linked list @@ -298,14 +316,7 @@ void Threads_Kill(tThread *Thread, int Status) if(Status == -1) { Thread->Status = THREAD_STAT_DEAD; - // Add to delete queue - if(gDeleteThreads) { - Thread->Next = gDeleteThreads; - gDeleteThreads = Thread; - } else { - Thread->Next = NULL; - gDeleteThreads = Thread; - } + Threads_AddToDelete( Thread ); } else { Thread->Status = THREAD_STAT_ZOMBIE; } diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index d605baa7..2d05bdcf 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -125,7 +125,8 @@ int main(int argc, char *argv[], char *envp[]) //SysDebug("pid = %i\n", pid); } else { - //waitpid(pid, K_WAITPID_DIE); + int status + waitpid(pid, &status); } } } diff --git a/Usermode/Libraries/libacess.so_src/core.asm b/Usermode/Libraries/libacess.so_src/core.asm index 97403223..9ce635c2 100644 --- a/Usermode/Libraries/libacess.so_src/core.asm +++ b/Usermode/Libraries/libacess.so_src/core.asm @@ -22,6 +22,7 @@ SYSCALL2 signal, SYS_SIGNAL SYSCALL0 yield, SYS_YIELD SYSCALL0 sleep, SYS_SLEEP SYSCALL1 wait, SYS_WAIT +SYSCALL2 waittid, SYS_WAITTID SYSCALL0 gettid, SYS_GETTID SYSCALL0 getpid, SYS_GETPID diff --git a/Usermode/include/acess/sys.h b/Usermode/include/acess/sys.h index 03a02bec..1b39c5c1 100644 --- a/Usermode/include/acess/sys.h +++ b/Usermode/include/acess/sys.h @@ -39,6 +39,8 @@ typedef struct s_sysFInfo t_sysFInfo; void _SysDebug(char *str, ...); // --- Proc --- void sleep(); +void wait(int miliseconds); + int waittid(int id, int *status); int clone(int flags, void *stack); int execve(char *path, char **argv, char **envp); // --- VFS ---