Get rid of THREAD_JOIN_IMPLEMENTED by adding thread_join() stub.
[pintos-anon] / src / threads / thread.h
1 #ifndef THREADS_THREAD_H
2 #define THREADS_THREAD_H
3
4 #include <debug.h>
5 #include <list.h>
6 #include <stdint.h>
7
8 /* States in a thread's life cycle. */
9 enum thread_status
10   {
11     THREAD_RUNNING,     /* Running thread. */
12     THREAD_READY,       /* Not running but ready to run. */
13     THREAD_BLOCKED,     /* Waiting for an event to trigger. */
14     THREAD_DYING        /* About to be destroyed. */
15   };
16
17 /* Thread identifier type.
18    You can redefine this to whatever type you like. */
19 typedef int tid_t;
20 #define TID_ERROR ((tid_t) -1)          /* Error value for tid_t. */
21
22 /* Thread priorities. */
23 #define PRI_MIN 0                       /* Lowest priority. */
24 #define PRI_DEFAULT 29                  /* Default priority. */
25 #define PRI_MAX 59                      /* Highest priority. */
26
27 /* A kernel thread or user process.
28
29    Each thread structure is stored in its own 4 kB page.  The
30    thread structure itself sits at the very bottom of the page
31    (at offset 0).  The rest of the page is reserved for the
32    thread's kernel stack, which grows downward from the top of
33    the page (at offset 4 kB).  Here's an illustration:
34
35         4 kB +---------------------------------+
36              |          kernel stack           |
37              |                |                |
38              |                |                |
39              |                V                |
40              |         grows downward          |
41              |                                 |
42              |                                 |
43              |                                 |
44              |                                 |
45              |                                 |
46              |                                 |
47              |                                 |
48              |                                 |
49              +---------------------------------+
50              |              magic              |
51              |                :                |
52              |                :                |
53              |               name              |
54              |              status             |
55         0 kB +---------------------------------+
56
57    The upshot of this is twofold:
58
59       1. First, `struct thread' must not be allowed to grow too
60          big.  If it does, then there will not be enough room for
61          the kernel stack.  Our base `struct thread' is only a
62          few bytes in size.  It probably should stay well under 1
63          kB.
64
65       2. Second, kernel stacks must not be allowed to grow too
66          large.  If a stack overflows, it will corrupt the thread
67          state.  Thus, kernel functions should not allocate large
68          structures or arrays as non-static local variables.  Use
69          dynamic allocation with malloc() or palloc_get_page()
70          instead.
71
72    The first symptom of either of these problems will probably be
73    an assertion failure in thread_current(), which checks that
74    the `magic' member of the running thread's `struct thread' is
75    set to THREAD_MAGIC.  Stack overflow will normally change this
76    value, triggering the assertion. */
77 /* The `elem' member has a dual purpose.  It can be an element in
78    the run queue (thread.c), or it can be an element in a
79    semaphore wait list (synch.c).  It can be used these two ways
80    only because they are mutually exclusive: only a thread in the
81    ready state is on the run queue, whereas only a thread in the
82    blocked state is on a semaphore wait list. */
83 struct thread
84   {
85     /* Owned by thread.c. */
86     tid_t tid;                          /* Thread identifier. */
87     enum thread_status status;          /* Thread state. */
88     char name[16];                      /* Name (for debugging purposes). */
89     uint8_t *stack;                     /* Saved stack pointer. */
90     int priority;                       /* Priority. */
91
92     /* Shared between thread.c and synch.c. */
93     list_elem elem;                     /* List element. */
94
95 #ifdef USERPROG
96     /* Owned by userprog/process.c. */
97     uint32_t *pagedir;                  /* Page directory. */
98 #endif
99
100     /* Owned by thread.c. */
101     unsigned magic;                     /* Detects stack overflow. */
102   };
103
104 void thread_init (void);
105 void thread_start (void);
106 void thread_tick (void);
107 void thread_print_stats (void);
108
109 typedef void thread_func (void *aux);
110 tid_t thread_create (const char *name, int priority, thread_func *, void *);
111
112 void thread_block (void);
113 void thread_unblock (struct thread *);
114
115 struct thread *thread_current (void);
116 tid_t thread_tid (void);
117 const char *thread_name (void);
118
119 void thread_exit (void) NO_RETURN;
120 void thread_yield (void);
121
122 void thread_join (tid_t);
123
124 void thread_set_priority (int);
125 int thread_get_priority (void);
126
127 #endif /* threads/thread.h */