view kernel/process.c3 @ 410:6aa9743ed362 tip

Reflect change in c3 public modifier
author Windel Bouwman
date Mon, 23 Feb 2015 21:06:04 +0100
parents ad6be5454067
children
line wrap: on
line source

module process;

import memory;
import kernel;

// process type definition:
type struct {
    int id;
    int status;
    process_t* next;
    process_t* prev;
} process_t;

var process_t* first_process;
var process_t* last_process;
var int next_pid;
var process_t* current;

public function void init()
{
    next_pid = 0;
    first_process = 0;
    last_process = 0;
}

/*
    Create a new process.
*/
public function process_t* create()
{
    var process_t* p;

    p = memory.alloc(sizeof(process_t));
    p->id = next_pid;
    p->status = 0; // Ready!
    p->next = 0;
    p->prev = 0;

    // Increment PID:
    next_pid = next_pid + 1;

    return p;
}

function void enqueue(process_t* p)
{
    // Store it in the list:
    if (first_process == cast<process_t*>(0))
    {
        first_process = p;
        last_process = p;
    }
    else
    {
        // Update pointers:
        last_process->next = p;
        p->prev = last_process;
        last_process = p;
    }
}

function void kill(process_t* p)
{
    // clean memory
}

public function process_t* byId(int id)
{
    // Perform lookup
    return 0;
}


public function void execute_next()
{
    var process_t *old;

    old = 0;

    if (old != current)
    {
        //execute(current);
    }

    kernel.panic();
}