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>
Macros | |
#define | MAX_PROCS 32768 |
Maximum number of processes that can be running at a time. | |
#define | HAS_UNBLOCKED_THREADS(proc) (proc->numThreads!=proc->numThreadsBlocked) |
Macro to check whethe a process has unblocked threads. | |
#define | NUM_UNBLOCKED_THREADS(proc) (proc->numThreads-proc->numThreadsBlocked) |
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. | |
#define | SAME_THREAD(thread1, thread2) (thread1->process->pid==thread2->process->pid&&thread1->tid==thread2->tid) |
Macro to check whether two threads have the same PID and TID. | |
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 | tasking_create_task (void *eip, void *cr3, char kmode, char param1_exists, void *param1_arg, char param2_exists, void *param2_arg, char isThread) |
void | tasking_init () |
char | tasking_is_privleged () |
pid_t | tasking_get_PID () |
int * | tasking_get_errno_address () |
pid_t | tasking_new_thread (void *start, pid_t pid, char param_exists, void *param_arg) |
void | switch_to_thread (Thread *thread) |
void | tasking_yield () |
void | tasking_block (thread_state newstate) |
void | tasking_unblock (pid_t pid, pid_t tid) |
void | tasking_exit (int code) |
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. | |
|
static |
Check whether a process is scheduled
index | The PID to check |
|
static |
Mark a process as scheduled
index | The PID to mark |
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 |
void tasking_create_task | ( | void * | eip, |
void * | cr3, | ||
char | kmode, | ||
char | param1_exists, | ||
void * | param1_arg, | ||
char | param2_exists, | ||
void * | param2_arg, | ||
char | isThread | ||
) |
Create a task
eip | The start address of the task |
cr3 | The address space of the task |
kmode | Whether the task is a kernel mode task |
param1_exists | Whether param1_arg is a valid value |
param1_arg | The thread's start function first parameter |
param2_exists | Whether param2_arg is a valid value |
param2_arg | 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, and param2_exists must be 0. |
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 |
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.
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, | ||
char | param_exists, | ||
void * | param_arg | ||
) |
Create a new thread
start | The start address of the task |
pid | The PID that gets the new thread |
param_exists | Whether param_arg is a valid value |
param_arg | The thread's start function parameter |
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 |