Fixed thread deletion when not explicitly killed.
authorJohn Hodge <[email protected]>
Fri, 25 Sep 2009 03:13:31 +0000 (11:13 +0800)
committerJohn Hodge <[email protected]>
Fri, 25 Sep 2009 03:13:31 +0000 (11:13 +0800)
Kernel/syscalls.c
Kernel/threads.c
Usermode/Applications/CLIShell_src/main.c
Usermode/Libraries/libacess.so_src/core.asm
Usermode/include/acess/sys.h

index 47200c6..ebfdbed 100644 (file)
@@ -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;
index 1644b50..1ccac9f 100644 (file)
@@ -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;
        }
index d605baa..2d05bdc 100644 (file)
@@ -125,7 +125,8 @@ int main(int argc, char *argv[], char *envp[])
                        //SysDebug("pid = %i\n", pid);\r
                }\r
                else {\r
-                       //waitpid(pid, K_WAITPID_DIE);\r
+                        int    status\r
+                       waitpid(pid, &status);\r
                }\r
        }\r
 }\r
index 9740322..9ce635c 100644 (file)
@@ -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
index 03a02be..1b39c5c 100644 (file)
@@ -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 ---

UCC git Repository :: git.ucc.asn.au