MyOS Kernel
tasking.h
Go to the documentation of this file.
1 
5 #ifndef KERN_TASKING_H
6 #define KERN_TASKING_H
7 
8 #include <stdint.h>
9 #include <sys/types.h>
10 #include "rpc.h"
11 
12 #ifndef TASKING_H
13 
17 typedef enum thread_state {
25 
26 #endif
27 
28 struct Thread;
29 
33 typedef struct Process {
34  char priv;
35  pid_t pid;
36  pid_t next_tid;
39  struct Thread* first_thread;
40 } Process;
41 
45 typedef struct Thread {
46  void* kernel_esp;
48  void* address_space;
49  pid_t tid;
51  int errno;
59  void* rpc_ret_buf;
60 } __attribute__((packed)) Thread;
61 
62 extern Thread* current_thread;
63 
74 void tasking_create_task(void* eip,void* address_space,char kmode,void* param1,void* param2,char isThread,char is_irq_handler);
78 void tasking_init();
88 pid_t tasking_get_PID();
93 pid_t tasking_get_TID();
107 pid_t tasking_new_thread(void* start,pid_t pid,void* param,char is_irq_handler);
108 
115 void tasking_exit(int code);
120 void tasking_block(thread_state newstate);
126 void tasking_unblock(pid_t pid,pid_t tid);
130 void tasking_yield();
136 void* tasking_get_address_space(pid_t pid);
137 
143 void tasking_set_rpc_calling_thread(pid_t pid,pid_t tid);
144 
151 pid_t tasking_get_rpc_calling_thread(pid_t* tid);
156 void tasking_set_rpc_ret_buf(void* buf);
157 
163 
167 void tasking_thread_exit();
168 
174 char tasking_check_proc_exists(pid_t pid);
175 
176 #endif
Definition: tasking.h:33
pid_t pid
The PID of this process.
Definition: tasking.h:35
int num_threads_blocked
The number of blocked threads in this process.
Definition: tasking.h:38
int num_threads
The number of threads in this process.
Definition: tasking.h:37
pid_t next_tid
The TID that the next created thread will use.
Definition: tasking.h:36
struct Thread * first_thread
A pointer to the head of the linked list of threads for this process.
Definition: tasking.h:39
char priv
Whether the process is privileged (can execute syscalls to acesss all of memory/has acess to IO ports...
Definition: tasking.h:34
Definition: tasking.h:45
thread_state state
The state of this thread. (running,ready to run,blocked,etc.)
Definition: tasking.h:50
Process * process
The thread's process.
Definition: tasking.h:56
void * rpc_ret_buf
The return buffer of the RPC call that the thread made.
Definition: tasking.h:59
struct Thread * next_thread_in_process
The next thread in the process.
Definition: tasking.h:52
void * address_space
The address space of this thread. (it is in here and not in the process to simplify the task switch a...
Definition: tasking.h:48
struct Thread * prev_ready_to_run
If the thread is in the ready to run list, this is the previous ready to run thread....
Definition: tasking.h:55
void * kernel_esp
The thread's kernel stack.
Definition: tasking.h:46
struct Thread * next_ready_to_run
If the thread is in the ready to run list, this is the next ready to run thread. (potentially in a di...
Definition: tasking.h:54
pid_t tid
The TID of this thread.
Definition: tasking.h:49
pid_t rpc_calling_tid
The TID of the thread that called this RPC (only used for RPC handler threads)
Definition: tasking.h:58
pid_t rpc_calling_pid
The PID of the thread that called this RPC (only used for RPC handler threads)
Definition: tasking.h:57
int errno
The errno value for this thread.
Definition: tasking.h:51
void * kernel_esp_top
The top of the thread's kernel stack.
Definition: tasking.h:47
struct Thread * prev_thread_in_process
The previous thread in the process.
Definition: tasking.h:53
void tasking_block(thread_state newstate)
Definition: tasking.c:257
void tasking_create_task(void *eip, void *address_space, char kmode, void *param1, void *param2, char isThread, char is_irq_handler)
Definition: tasking.c:93
pid_t tasking_get_rpc_calling_thread(pid_t *tid)
Definition: tasking.c:384
pid_t tasking_new_thread(void *start, pid_t pid, void *param, char is_irq_handler)
Definition: tasking.c:160
int * tasking_get_errno_address()
Definition: tasking.c:156
void tasking_init()
Definition: tasking.c:136
void * tasking_get_rpc_ret_buf()
Definition: tasking.c:396
char tasking_is_privleged()
Definition: tasking.c:144
thread_state
Definition: tasking.h:17
@ THREAD_BLOCKED
The state of a generically blocked thread.
Definition: tasking.h:21
@ THREAD_RUNNING
The state of a running thread.
Definition: tasking.h:18
@ THREAD_WAITING_FOR_RPC_INIT
The state of a thread waiting for a process to fully initilaize it's RPC functions.
Definition: tasking.h:23
@ THREAD_EXITED
The state of an exited thread.
Definition: tasking.h:20
@ THREAD_WAITING_FOR_RPC
The state of a thread waiting for an RPC call to return.
Definition: tasking.h:22
@ THREAD_READY
The state of a ready to run thread.
Definition: tasking.h:19
pid_t tasking_get_TID()
Definition: tasking.c:152
void tasking_yield()
Definition: tasking.c:227
void * tasking_get_address_space(pid_t pid)
Definition: tasking.c:374
void tasking_unblock(pid_t pid, pid_t tid)
Definition: tasking.c:321
pid_t tasking_get_PID()
Definition: tasking.c:148
Thread * current_thread
Currently running thread.
Definition: tasking.c:22
void tasking_exit(int code)
Definition: tasking.c:336
void tasking_set_rpc_calling_thread(pid_t pid, pid_t tid)
Definition: tasking.c:378
void tasking_thread_exit()
Definition: tasking.c:400
void tasking_set_rpc_ret_buf(void *buf)
Definition: tasking.c:389
char tasking_check_proc_exists(pid_t pid)
Definition: tasking.c:404