summaryrefslogtreecommitdiffstats
path: root/src/threads
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-02-21 19:55:30 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-02-21 19:56:03 +0100
commit83b6103986c65ad580b4b7f038660bfa01f1d087 (patch)
tree61885e8c578113de674be0ef5352390fd1a62092 /src/threads
parentec5c4ad0b9cb68c0405728c913c42a3f5f412b37 (diff)
downloadpintos-83b6103986c65ad580b4b7f038660bfa01f1d087.tar.gz
push child to parents list of children
Diffstat (limited to 'src/threads')
-rw-r--r--src/threads/thread.c3
-rw-r--r--src/threads/thread.h24
2 files changed, 26 insertions, 1 deletions
diff --git a/src/threads/thread.c b/src/threads/thread.c
index 43dd8e3..3112a71 100644
--- a/src/threads/thread.c
+++ b/src/threads/thread.c
@@ -436,6 +436,9 @@ init_thread (struct thread *t, const char *name, int priority)
strlcpy (t->name, name, sizeof t->name);
t->stack = (uint8_t *) t + PGSIZE;
t->priority = priority;
+#ifdef USERPROG
+ list_init (&t->children);
+#endif
t->magic = THREAD_MAGIC;
}
diff --git a/src/threads/thread.h b/src/threads/thread.h
index e3c426d..b822b64 100644
--- a/src/threads/thread.h
+++ b/src/threads/thread.h
@@ -4,6 +4,7 @@
#include <debug.h>
#include <list.h>
#include <stdint.h>
+#include "threads/synch.h"
#define MAX_FDS 128 /* Max number of file descriptors per thread */
@@ -21,6 +22,24 @@ enum thread_status
typedef int tid_t;
#define TID_ERROR ((tid_t) -1) /* Error value for tid_t. */
+/* The relationship between a parent and child process.
+ It is setup by the child in
+ The child reports its exit status by setting exit_status
+ and upping exit_sema.
+ The parent places the parent_child element in its list of children.
+*/
+struct parent_child
+ {
+ struct list_elem elem; // owned by the parent
+
+ struct semaphore exit_sema;
+
+ struct lock l;
+ int exit_status;
+ int alive_count;
+
+ };
+
/* Thread priorities. */
#define PRI_MIN 0 /* Lowest priority. */
#define PRI_DEFAULT 31 /* Default priority. */
@@ -98,7 +117,10 @@ struct thread
#ifdef USERPROG
/* Owned by userprog/process.c. */
uint32_t *pagedir; /* Page directory. */
- struct file **fds; /* Pointer to array of file descriptors. */
+ struct file **fds; /* Pointer to array of file descriptors. */
+
+ struct parent_child parent; // one parent
+ struct list children; // multiple children
#endif
/* Owned by thread.c. */