MyOS Kernel
|
#include "cpu/halt.h"
#include "cpu/paging.h"
#include "cpu/serial.h"
#include "cpu/tasking_helpers.h"
#include "kmalloc.h"
#include "tasking.h"
#include <sys/types.h>
#include <string.h>
Macros | |
#define | MAX_PROCS 32768 |
Maximum number of processes that can be running at a time. | |
#define | HAS_UNBLOCKED_THREADS(proc) (proc->num_threads!=proc->num_threads_blocked) |
Macro to check whethe a process has unblocked threads. | |
#define | NUM_UNBLOCKED_THREADS(proc) (proc->num_threads-proc->num_threads_blocked) |
Macro to get the number of unblocked threads for a process. | |
#define | SAME_PROC(thread1, thread2) (thread1->process->pid==thread2->process->pid) |
Macro to check whether two threads have the same PID. | |
Functions | |
static char | is_proc_scheduled (pid_t index) |
static void | mark_proc_scheduled (pid_t index) |
static void | unmark_proc_scheduled (pid_t index) |
void | schedule_thread (Thread *thread) |
void | tasking_create_task (void *eip, void *address_space, char kmode, void *param1, void *param2, char isThread) |
void | tasking_init () |
char | tasking_is_privleged () |
pid_t | tasking_get_PID () |
pid_t | tasking_get_TID () |
int * | tasking_get_errno_address () |
pid_t | tasking_new_thread (void *start, pid_t pid, void *param) |
static Thread * | get_next_ready_thread (Thread *thread, Thread *thread_to_skip) |
void | switch_to_thread (Thread *thread) |
void | tasking_yield () |
void | tasking_block (thread_state newstate) |
static Thread * | get_thread (pid_t pid, pid_t tid) |
void | tasking_unblock (pid_t pid, pid_t tid) |
void | tasking_exit (int code) |
void * | tasking_get_address_space (pid_t pid) |
void | tasking_set_rpc_calling_thread (pid_t pid, pid_t tid) |
pid_t | tasking_get_rpc_calling_thread (pid_t *tid) |
void | tasking_set_rpc_ret_buf (void *buf) |
void * | tasking_get_rpc_ret_buf () |
void | tasking_thread_exit () |
char | tasking_check_proc_exists (pid_t pid) |
Variables | |
pid_t | next_pid =0 |
PID to use for the next created process. | |
size_t | num_procs =0 |
Number of non-exited processes. | |
Process | processes [MAX_PROCS] |
Array pf processes by PID. | |
char | proc_schedule_bmap [MAX_PROCS/8] |
Bitmap of what processes are scheduled. | |
Thread * | current_thread |
Currently running thread. | |
static Thread * | ready_to_run_head =NULL |
Head of the linked list of ready to run threads. | |
static Thread * | ready_to_run_tail =NULL |
Tail of the linked list of ready to run threads. | |
Get the next ready thread in a list of threads, starting at the specified thread's next thread
thread | The start thread |
thread_to_skip | A thread to skip even if it's ready |
|
static |
Get a thread
pid | The PID of the thread |
tid | The TID of the thread |
|
static |
Check whether a process is scheduled
index | The PID to check |
|
static |
Mark a process as scheduled
index | The PID to mark |
void schedule_thread | ( | Thread * | thread | ) |
Schedules a thread if the thread's prcess does not have a scheduled thread
thread | The thread to schedule |
void switch_to_thread | ( | Thread * | thread | ) |
Switch to a thread and schedule the next ready thread in the current process, if there is one.
thread | The thread to switch to |
void tasking_block | ( | thread_state | newstate | ) |
Block the current thread & yield
newstate | The state to block it in |
char tasking_check_proc_exists | ( | pid_t | pid | ) |
Check if a process exists
pid | The param of the process to check |
void tasking_create_task | ( | void * | eip, |
void * | address_space, | ||
char | kmode, | ||
void * | param1, | ||
void * | param2, | ||
char | isThread | ||
) |
Create a task
eip | The start address of the task |
address_space | The address space of the task |
kmode | Whether the task is a kernel mode task |
param1 | The thread's start function first parameter |
param2 | The thread's start function second parameter |
isThread | Whether we are creating a new process or a thread in a process. If we are creating a theead, param2_arg becomes the PID for the newly created thread. |
void tasking_exit | ( | int | code | ) |
Terminate the current thread If the main thread terminates, the whole process terminates.
code | The exit code of the thread |
void* tasking_get_address_space | ( | pid_t | pid | ) |
Get the address_space of a process
pid | the PID of the process |
int* tasking_get_errno_address | ( | ) |
Get the adddress of errno for the current thread
pid_t tasking_get_PID | ( | ) |
Get the PID of the current thread.
pid_t tasking_get_rpc_calling_thread | ( | pid_t * | tid | ) |
Get the RPC calling thread for the current thread
tid | A pointer to a pid_t to store the return TID |
void* tasking_get_rpc_ret_buf | ( | ) |
Get the RPC return buffer for the current thread
pid_t tasking_get_TID | ( | ) |
Get the TID of the current thread.
void tasking_init | ( | ) |
Initialize tasking
char tasking_is_privleged | ( | ) |
Check whether the current process is privleged
pid_t tasking_new_thread | ( | void * | start, |
pid_t | pid, | ||
void * | param | ||
) |
Create a new thread
start | The start address of the task |
pid | The PID that gets the new thread |
param | The thread's start function parameter |
void tasking_set_rpc_calling_thread | ( | pid_t | pid, |
pid_t | tid | ||
) |
Set the RPC calling thread for an RPC handler thread to the current threasd
pid | The PID of the handler thread |
tid | The TID of the handler thread |
void tasking_set_rpc_ret_buf | ( | void * | buf | ) |
Set the RPC return buffer for the calling thread
buf | The return buffer |
void tasking_thread_exit | ( | ) |
Terminate the current thread
void tasking_unblock | ( | pid_t | pid, |
pid_t | tid | ||
) |
Unblock a thread
pid | The PID that contains the thread to unblock |
tid | The TID in the process to unblock. |
void tasking_yield | ( | ) |
Yield to the next ready thread in any process
|
static |
Unmark a process as scheduled
index | The PID to unmark |