Redo and improve thread scheduling startup.
[pintos-anon] / src / threads / thread.h
1 #ifndef HEADER_THREAD_H
2 #define HEADER_THREAD_H 1
3
4 #include <stdint.h>
5 #include "debug.h"
6 #include "list.h"
7
8 #ifdef USERPROG
9 #include "addrspace.h"
10 #endif
11
12 enum thread_status 
13   {
14     THREAD_RUNNING,
15     THREAD_READY,
16     THREAD_BLOCKED,
17     THREAD_DYING
18   };
19
20 struct thread 
21   {
22     /* These members are owned by the thread_*() functions. */
23     enum thread_status status;          /* Thread state. */
24     char name[16];                      /* Name (for debugging purposes). */
25     uint8_t *stack;                     /* Saved stack pointer. */
26     list_elem rq_elem;                  /* Run queue list element. */
27
28 #ifdef USERPROG
29     /* These members are owned by the addrspace_*() functions. */
30     uint32_t *pagedir;                  /* Page directory. */
31 #endif
32     
33     /* Marker to detect stack overflow. */
34     unsigned magic;                     /* Always set to THREAD_MAGIC. */
35   };
36
37 void thread_init (void);
38 void thread_start (void);
39
40 typedef void thread_func (void *aux);
41 struct thread *thread_create (const char *name, thread_func *, void *);
42 #ifdef USERPROG
43 bool thread_execute (const char *filename);
44 #endif
45
46 void thread_wake (struct thread *);
47 const char *thread_name (struct thread *);
48
49 struct thread *thread_current (void);
50 void thread_exit (void) NO_RETURN;
51 void thread_yield (void);
52 void thread_sleep (void);
53
54 #endif /* thread.h */