[MULTITASKING] Processes

This commit is contained in:
2016-12-16 19:22:33 +01:00
parent 5e8fbcbb78
commit 5ca2b6994a
8 changed files with 177 additions and 8 deletions

34
kernel/include/process.h Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
typedef struct process_st process_t;
#include <stdint.h>
#include <thread.h>
#include <mem.h>
typedef struct process_st
{
uint64_t pid;
uint64_t state;
uint64_t status;
struct process_st *parent;
page_table *P4;
LIST(struct process_st, children);
LIST(struct process_st, siblings);
LIST(thread_t, threads);
} process_t;
#define PROC_STATE_READY 1
#define PROC_STATE_RUNNING 2
#define PROC_STATE_ZOMBIE 3
#define PROC_STATE_DONE 4
#define process_alive(proc) ((proc)->state == PROC_STATE_READY || (proc)->state == PROC_STATE_RUNNING)
process_t *current_process;
#define get_current_process() (current_process)
#define set_current_process(proc) (current_process = (proc))
process_t *process_spawn(process_t *parent);
void process_attach(process_t *proc, thread_t *th);
void switch_process(process_t *proc);
void process_exit(process_t *proc, uint64_t status);
void process_free(process_t *proc);

View File

@@ -1,6 +1,8 @@
#pragma once
typedef struct thread_st thread_t;
#include <stdint.h>
#include <list.h>
#include <process.h>
#define THREAD_STACK_SIZE 0x1000-sizeof(thread_t)
@@ -9,6 +11,8 @@ typedef struct thread_st
uint64_t stack_pointer; // Top of the kernel stack for thread
uint64_t tid;
uint64_t state;
process_t *process;
LIST(struct thread_st, process_threads);
LIST(struct thread_st, ready_queue);
} thread_t;