Retro Rocket Kernel BASIC-Powered Operating System

Data Structures | Typedefs | Enumerations | Functions
taskswitch.h File Reference

Handles processes and multitasking. More...

## Data Structures
struct | process_t
struct | proc_id_t
| Process identifier struct. Used to identify processes by ID in the hash map only, contains the id and a pointer to the actual process_t struct. More...
struct | idle_timer_t
| An idle timer. More...

## Typedefs
typedef uint32_t | pid_t
typedef uint32_t | uid_t
typedef uint32_t | gid_t
typedef uint8_t | cpu_id_t
typedef void(* | proc_idle_timer_t) (void)

## Enumerations
enum | process_state_t { PROC_RUNNING , PROC_IDLE , PROC_DELET }
| Represents the current state of a process. More...
enum | idle_type_t { IDLE_FOREGROUND , IDLE_BACKGROUND }
| Types of idle task. More...

## Functions
process_t * | proc_load (const char *fullpath, struct console *cons, pid_t parent_pid, const char *csd)
| Load a new BASIC process. More...
process_t * | proc_find (pid_t pid)
| Find a process by ID. More...
process_t * | proc_cur ()
| Return detail of current process. More...
void | proc_wait (process_t *proc, pid_t otherpid)
| Mark a process as waiting for another process to complete. More...
void | proc_run (process_t *proc)
| Run BASIC program for one atomic cycle. More...
int | proc_ended (process_t *proc)
| Returns true if the program has ended. More...
void | proc_kill (process_t *proc)
| Kill a process. More...
bool | proc_kill_id (pid_t id)
| Kill a process by ID. More...
void | proc_show_list ()
| Display a diagnostic list of all processes. More...
void | proc_loop ()
| Run the process scheduling loop. More...
void | proc_timer ()
| Change to next scheduled process. More...
int64_t | proc_total ()
| Returns the total number of running processes. More...
pid_t | proc_id (int64_t index)
| Returns the id of a process by index number. More...
void | proc_register_idle (proc_idle_timer_t handler, idle_type_t type)
| Register a function to be called periodically during idle time. More...
const char * | proc_set_csd (process_t *proc, const char *csd)
| Change CSD (currently selected directory) of process. More...
void | init_process ()

## Detailed Description

Handles processes and multitasking.

Author
  Craig Edwards (craig.nosp@m.edwa.nosp@m.rds@b.nosp@m.rain.nosp@m.box.c.nosp@m.c)

Copyright
  Copyright (c) 2012-2023

## Typedef Documentation

## ◆ cpu_id_t

typedef uint8_t cpu_id_t

## ◆ gid_t

typedef uint32_t gid_t

## ◆ pid_t

typedef uint32_t pid_t

## ◆ proc_idle_timer_t

typedef void(* proc_idle_timer_t) (void)

## ◆ uid_t

typedef uint32_t uid_t

## Enumeration Type Documentation

## ◆ idle_type_t

enum idle_type_t

Types of idle task.

Enumerator
IDLE_FOREGROUND |
IDLE_BACKGROUND |

## ◆ process_state_t

enum process_state_t

Represents the current state of a process.

Enumerator
PROC_RUNNING |
PROC_IDLE |
PROC_DELET |

## Function Documentation

## ◆ init_process()

void init_process | ( |  | ) |

## ◆ proc_cur()

process_t* proc_cur | ( |  | ) |

Return detail of current process.

Returns
  process_t* process detail or NULL if no current process

## ◆ proc_ended()

int proc_ended | ( | process_t * | proc | ) |

Returns true if the program has ended.

Parameters

  proc | process

Returns
  int true if ended

## ◆ proc_find()

process_t* proc_find | ( | pid_t | pid | ) |

Find a process by ID.

Parameters

  pid | process ID

Returns
  process_t* process detail or NULL if not found

## ◆ proc_id()

pid_t proc_id | ( | int64_t | index | ) |

Returns the id of a process by index number.

Parameters

  index | index number of process to find between 0 and proc_total()

Returns
  pid_t process id

## ◆ proc_kill()

void proc_kill | ( | process_t * | proc | ) |

Kill a process.

Parameters

  proc | process to kill

## ◆ proc_kill_id()

bool proc_kill_id | ( | pid_t | id | ) |

Kill a process by ID.

Note
  Cannot be used to kill the current process from itself!

Parameters

  id | Process ID to kill

Returns
  true if found and killed

## ◆ proc_load()

process_t* proc_load | ( | const char * | fullpath,
|  | struct console * | cons,
|  | pid_t | parent_pid,
|  | const char * | csd
| ) |  |

Load a new BASIC process.

Parameters

  fullpath | fully qualified path to file
  cons | console
  parent_pid | parent PID, or 0
  csd | Currently selected directory

Returns
  process_t* new process details

## ◆ proc_loop()

void proc_loop | ( |  | ) |

Run the process scheduling loop.

Note
  Does not return

## ◆ proc_register_idle()

void proc_register_idle | ( | proc_idle_timer_t | handler,
|  | idle_type_t | type
| ) |  |

Register a function to be called periodically during idle time.

Parameters

  handler | handler function, void(void)
  type | type of idle to register

## ◆ proc_run()

void proc_run | ( | process_t * | proc | ) |

Run BASIC program for one atomic cycle.

Parameters

  proc | process to execute

## ◆ proc_set_csd()

const char* proc_set_csd | ( | process_t * | proc,
|  | const char * | csd
| ) |  |

Change CSD (currently selected directory) of process.

Note
  No validation of the path is peformed, this must be done extnerally to this function by validating the file information on VFS.

Parameters

  proc | Process struct
  csd | current directory

Returns
  const char* new current directory

## ◆ proc_show_list()

void proc_show_list | ( |  | ) |

Display a diagnostic list of all processes.

## ◆ proc_timer()

void proc_timer | ( |  | ) |

Change to next scheduled process.

Note
  Uses the round robin scheduling algorithm

## ◆ proc_total()

int64_t proc_total | ( |  | ) |

Returns the total number of running processes.

Returns
  int64_t number of running processes

## ◆ proc_wait()

void proc_wait | ( | process_t * | proc,
|  | pid_t | otherpid
| ) |  |

Mark a process as waiting for another process to complete.

Parameters

  proc | process to mark as waiting
  otherpid | other process ID to wait on, must exist.