diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..ff4ad4d6ef8dbcca56d800a77b44365994f41043 --- /dev/null +++ b/src/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "typeindex": "c", + "typeinfo": "c" + } +} \ No newline at end of file diff --git a/src/devices/timer.c b/src/devices/timer.c index fee0b5ba7ffd089398a7b88f7d3a89836c2d3f31..4c3cebae0329bf0b2e858d06e0b0d28cd22720a7 100644 --- a/src/devices/timer.c +++ b/src/devices/timer.c @@ -32,8 +32,8 @@ static void real_time_sleep (int64_t num, int32_t denom); struct list sleep_list; bool comparator(struct list_elem *a, struct list_elem *b, int *aux){ - struct thread *t1 = list_entry(a, struct thread, elem); - struct thread *t2 = list_entry(b, struct thread, elem); + struct thread *t1 = list_entry(a, struct thread, sleep_elem); + struct thread *t2 = list_entry(b, struct thread, sleep_elem); return (t1->wakeupTime < t2->wakeupTime); } @@ -112,7 +112,7 @@ timer_sleep (int64_t ticks) //tar in ticks som är antalet ticks tråden ska s //timer_elapsed(start) + ticks; - list_insert_ordered(&sleep_list,&thread_current()->elem,comparator, NULL); + list_insert_ordered(&sleep_list,&thread_current()->sleep_elem,comparator, NULL); //intr_set_level(INTR_OFF); enum intr_level level; level = intr_disable(); @@ -165,7 +165,7 @@ timer_interrupt (struct intr_frame *args UNUSED) while (e1 != list_tail(&sleep_list)) { - struct thread *t1 = list_entry(e1, struct thread, elem); + struct thread *t1 = list_entry(e1, struct thread, sleep_elem); e2 = list_next(e1); @@ -174,6 +174,9 @@ timer_interrupt (struct intr_frame *args UNUSED) list_remove(e1); thread_unblock(t1); } + else { + break; + } e1 = e2; diff --git a/src/threads/thread.c b/src/threads/thread.c index b9edabc83fcd6801d30b23f584f15f1b411ad042..215c81684c3b7eb278be9801f8f9b992e245da46 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -24,6 +24,8 @@ that are ready to run but not actually running. */ static struct list ready_list; +struct list relation_list; + /* Idle thread. */ static struct thread *idle_thread; @@ -87,6 +89,7 @@ thread_init (void) lock_init (&tid_lock); list_init (&ready_list); + list_init (&relation_list); /* Set up a thread structure for the running thread. */ initial_thread = running_thread (); @@ -279,6 +282,8 @@ thread_exit (void) ASSERT (!intr_context ()); #ifdef USERPROG + printf("%s: exit(%d\n", thread-name, thread-exit-value); + for (int i = 2; i < 130; i++) { if (thread_current()->fileArray[i] != 0) diff --git a/src/threads/thread.h b/src/threads/thread.h index dd72c6faa98af320cc2c608517e106940da468dc..6730d355555b2e653b9a6bda49adf51ff418f6ef 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -91,7 +91,10 @@ struct thread /* Shared between thread.c and synch.c. */ struct list_elem elem; /* List element. */ + struct list_elem sleep_elem; /* Sleep element. */ int64_t wakeupTime; + //struct relationblock relation; + struct list relation_list; #ifdef USERPROG @@ -99,13 +102,23 @@ struct thread uint32_t *pagedir; /* Page directory. */ struct file *fileArray[130]; //Array med pekare till filer - #endif /* Owned by thread.c. */ unsigned magic; /* Detects stack overflow. */ }; +struct relationblock { + int exit_status; //exit status, -1 om det kraschar + int alive_count; //hur många i familjen som lever, 2 från start + int exec_status; + //parent tid? + tid_t parent; + //child tid? + tid_t child; + struct list_elem relation_elem; +}; + /* If false (default), use round-robin scheduler. If true, use multi-level feedback queue scheduler. Controlled by kernel command-line option "-o mlfqs". */ diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 0bb1987d38e87dab396c7ca2ffeb22e3d7146e75..1abf866e46a36bdf3fff0e3ae7eb25546466f17a 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -3,6 +3,8 @@ #include <syscall-nr.h> #include "threads/interrupt.h" #include "threads/thread.h" +#include "threads/synch.h" +#include "list.h" static void syscall_handler(struct intr_frame *); @@ -24,9 +26,33 @@ syscall_handler(struct intr_frame *f UNUSED) power_off(); break; } + case SYS_EXEC: + { + //PEKARE till relation, relation är en struct, denna struct relation läggs in i listan som är i tråden, exit status, exec status + + const char *file = *(const char **)(f->esp + 4); + tid_t child_pid = process_execute(file); + + struct semaphore s; + sema_init(&s, list_size(&thread_current()->relation_list)); + sema_up(&s); + //LOOP TILLS CHILD LOADED + sema_down(&s); + //lägg in struct relation i listan + //kanske malloc + struct relationblock relationship; + relationship.parent = thread_current()->tid; + //relationship.child = child tid + relationship.alive_count = 2; + list_push_front(&thread_current()->relation_list, &relationship.relation_elem); + + f->eax = child_pid; + break; + } case SYS_EXIT: { thread_exit(); + //f->eax = exit status break; } case SYS_OPEN: