MyOS Kernel
tasking.h File Reference
#include <stdint.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  Process
 
struct  Thread
 

Enumerations

enum  thread_state { THREAD_RUNNING, THREAD_READY, THREAD_EXITED, THREAD_BLOCKED }
 

Functions

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 tasking_exit (int code)
 
void tasking_block (thread_state newstate)
 
void tasking_unblock (pid_t pid, pid_t tid)
 
void tasking_yield ()
 

Variables

Threadcurrent_thread
 Currently running thread.
 

Enumeration Type Documentation

◆ thread_state

Represents the state of a thread

Enumerator
THREAD_RUNNING 

The state of a running thread.

THREAD_READY 

The state of a ready to run thread.

THREAD_EXITED 

The state of an exited thread.

THREAD_BLOCKED 

The state of a generically blocked thread.

Function Documentation

◆ tasking_block()

void tasking_block ( thread_state  newstate)

Block the current thread & yield

Parameters
newstateThe state to block it in

◆ tasking_create_task()

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

Parameters
eipThe start address of the task
cr3The address space of the task
kmodeWhether the task is a kernel mode task
param1_existsWhether param1_arg is a valid value
param1_argThe thread's start function first parameter
param2_existsWhether param2_arg is a valid value
param2_argThe thread's start function second parameter/
isThreadWhether 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.

◆ tasking_exit()

void tasking_exit ( int  code)

Terminate the current thread If the main thread terminates, the whole process terminates.

Note
Currently, calling tasking_exit from any thread terminates the whole process.
Parameters
codeThe exit code of the thread

◆ tasking_get_errno_address()

int* tasking_get_errno_address ( )

Get the adddress of errno for the current thread

Returns
The address of errno

◆ tasking_get_PID()

pid_t tasking_get_PID ( )

Get the PID of the current thread.

Returns
The current thread's PID

◆ tasking_init()

void tasking_init ( )

Initialize tasking

◆ tasking_is_privleged()

char tasking_is_privleged ( )

Check whether the current process is privleged

Returns
whether the current process is privleged

◆ tasking_new_thread()

pid_t tasking_new_thread ( void *  start,
pid_t  pid,
char  param_exists,
void *  param_arg 
)

Create a new thread

Parameters
startThe start address of the task
pidThe PID that gets the new thread
param_existsWhether param_arg is a valid value
param_argThe thread's start function parameter
Returns
the TID of the thread

◆ tasking_unblock()

void tasking_unblock ( pid_t  pid,
pid_t  tid 
)

Unblock a thread

Parameters
pidThe PID that contains the thread to unblock
tidThe TID in the process to unblock.

◆ tasking_yield()

void tasking_yield ( )

Yield to the next ready thread in any process