Merge branch 'master' into signal-dev
[lunaix-os.git] / lunaix-os / kernel / sched.c
index 442921ebccfb444fd13d1374988f5fdbe7cef108..026fb515a8dbfbc34410e868de18ccad40b7b308 100644 (file)
@@ -1,12 +1,14 @@
 #include <arch/x86/interrupts.h>
 #include <arch/x86/tss.h>
+
 #include <hal/apic.h>
 #include <hal/cpu.h>
+
 #include <lunaix/mm/kalloc.h>
 #include <lunaix/mm/vmm.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
-
+#include <lunaix/signal.h>
 #include <lunaix/spike.h>
 #include <lunaix/status.h>
 #include <lunaix/syscall.h>
@@ -58,9 +60,11 @@ run(struct proc_info* proc)
 
     apic_done_servicing();
 
-    asm volatile("pushl %0\n"
+    signal_dispatch();
+
+    asm volatile("movl %0, %%eax\n"
                  "jmp soft_iret\n" ::"r"(&__current->intr_ctx)
-                 : "memory");
+                 : "eax", "memory");
 }
 
 void
@@ -145,11 +149,12 @@ _wait(pid_t wpid, int* status, int options)
         return -1;
     }
 
+    wpid = wpid ? wpid : -__current->pgid;
     cpu_enable_interrupt();
 repeat:
     llist_for_each(proc, n, &__current->children, siblings)
     {
-        if (!~wpid || proc->pid == wpid) {
+        if (!~wpid || proc->pid == wpid || proc->pgid == -wpid) {
             if (proc->state == PROC_TERMNAT && !options) {
                 status_flags |= PROCTERM;
                 goto done;
@@ -205,8 +210,10 @@ push_process(struct proc_info* process)
 
     process = &sched_ctx._procs[index];
 
-    // make sure the address is in the range of process table
+    // make sure the reference is relative to process table
     llist_init_head(&process->children);
+    llist_init_head(&process->grp_member);
+
     // every process is the child of first process (pid=1)
     if (process->parent) {
         llist_append(&process->parent->children, &process->siblings);