init
This commit is contained in:
parent
16a9b047ae
commit
f896ac89e1
5 changed files with 279 additions and 0 deletions
128
doubly_linked_list.c
Normal file
128
doubly_linked_list.c
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
#include <stdbool.h>
|
||||
#include "scheduler.h"
|
||||
#include "doubly_linked_list.h"
|
||||
|
||||
/**
|
||||
* \brief Checks whether a run_queue is empty
|
||||
*
|
||||
* \param rq Pointer to the run_queue
|
||||
*
|
||||
* \returns `true` iff the run_queue is empty
|
||||
*/
|
||||
bool stud_rq_empty(struct run_queue const *rq) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Creates a task
|
||||
*
|
||||
* \param pid The pid of the new task
|
||||
* \param state Default state of the task
|
||||
*
|
||||
* \return A pointer to the new task, `NULL` if failed
|
||||
*/
|
||||
|
||||
struct task *stud_task_create(int pid, enum states state) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Frees/destroys a task This function assumes the task has already been
|
||||
* removed from any run queue. It does not handle linked list operations
|
||||
* or modifications to the run queue.
|
||||
*
|
||||
* \param task Pointer to the task to-be-destroyed
|
||||
*/
|
||||
void stud_task_free(struct task *task) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Frees all the elements of the `run_queue` and empties it.
|
||||
* `rq` itself should NOT be freed. After calling this function,
|
||||
* `rq` must simply be an empty `run_queue`.
|
||||
*
|
||||
* \param rq Pointer to the run_queue to-be-destroyed
|
||||
*/
|
||||
void stud_rq_destroy(struct run_queue *rq) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Tries to find a task in a run_queue by its PID
|
||||
*
|
||||
* \param rq Pointer to the run_queue
|
||||
* \param pid PID of the wanted task
|
||||
*
|
||||
* \returns Pointer to the task, `NULL` if failed
|
||||
*/
|
||||
struct task *stud_rq_find(struct run_queue *rq, int pid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the head of the `run_queue`.
|
||||
*
|
||||
* \param rq Pointer to the run_queue
|
||||
*/
|
||||
struct task *stud_rq_head(struct run_queue *rq) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the tail of the `run_queue`.
|
||||
*
|
||||
* \param rq Pointer to the run_queue
|
||||
*/
|
||||
struct task *stud_rq_tail(struct run_queue *rq) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Enqueues a task on the given run_queue. The head stays where it is
|
||||
* and the new task is put at the END of the list.
|
||||
*
|
||||
* \param rq Pointer to the run_queue
|
||||
* \param task The task to-be-enqueued
|
||||
*
|
||||
* \returns `true` iff successful
|
||||
*/
|
||||
bool stud_rq_enqueue(struct run_queue *rq, struct task *task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Enqueues a task into the run_queue sorted by ascending runtime.
|
||||
*
|
||||
* \param rq Pointer to the run_queue
|
||||
* \param task The task to be inserted
|
||||
*
|
||||
* \returns `true` if successful
|
||||
*/
|
||||
bool stud_rq_enqueue_sorted(struct run_queue* rq, struct task* task){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Prepends a task on the given run_queue. The head of the list MUST be
|
||||
* moved to the new task!
|
||||
*
|
||||
* \param rq Pointer the run_queue
|
||||
* \param task The task to-be-prepended
|
||||
*
|
||||
* \returns `true` iff successful
|
||||
*/
|
||||
bool stud_rq_prepend(struct run_queue *rq, struct task *task) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Computes the length of a `run_queue`
|
||||
*
|
||||
* \param rq The run_queue
|
||||
*
|
||||
* \return The length of `rq`
|
||||
*/
|
||||
size_t stud_rq_length(struct run_queue *rq) {
|
||||
return false;
|
||||
}
|
||||
5
fcfs.c
Normal file
5
fcfs.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include "fcfs.h"
|
||||
|
||||
void sched_fcfs(struct proc *list, int *schedule) {
|
||||
return;
|
||||
}
|
||||
40
scheduler.h
Normal file
40
scheduler.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef SCHEDULER_H__
|
||||
#define SCHEDULER_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define QUANTUM 10
|
||||
|
||||
enum states {
|
||||
BLOCKED = 0,
|
||||
RUNNING,
|
||||
READY,
|
||||
TERMINATED,
|
||||
};
|
||||
|
||||
enum events {
|
||||
start = 0,
|
||||
wait,
|
||||
wake_up,
|
||||
terminate,
|
||||
clock_tick,
|
||||
};
|
||||
|
||||
struct task {
|
||||
int pid;
|
||||
enum states state;
|
||||
struct task* prev;
|
||||
struct task* next;
|
||||
int runtime;
|
||||
};
|
||||
|
||||
struct run_queue {
|
||||
struct task* head;
|
||||
size_t n_tasks;
|
||||
int time_counter;
|
||||
};
|
||||
|
||||
#endif // SCHEDULER_H__
|
||||
101
scheduler_round_robin.c
Normal file
101
scheduler_round_robin.c
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include "scheduler.h"
|
||||
#include "scheduler_round_robin.h"
|
||||
#include "doubly_linked_list.h"
|
||||
|
||||
/**
|
||||
* \brief Enqueues a process in READY state
|
||||
*
|
||||
* \param rq The scheduler's run queue
|
||||
* \param pid The process to be enqueued
|
||||
*/
|
||||
void stud_RR_start(struct run_queue* rq, int pid) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Elects and starts a process from the run queue. The running process MUST be placed
|
||||
* at the head of `rq` if it is not already there.
|
||||
*
|
||||
* \param rq The scheduler's run queue
|
||||
*/
|
||||
void stud_RR_elect(struct run_queue* rq) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Terminates the current running process (i.e. rq->head) and places it at the BACK
|
||||
* of the run_queue.
|
||||
*
|
||||
* \param rq The scheduler's run queue
|
||||
*/
|
||||
void stud_RR_terminate(struct run_queue* rq) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Performs a clock tick as specified by RR.
|
||||
*
|
||||
* \param rq The scheduler's run queue
|
||||
*/
|
||||
void stud_RR_clock_tick(struct run_queue* rq) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Sets the state of the running process to BLOCKED, moves it to the BACK of the
|
||||
* run_queue, and elects and runs a new process.
|
||||
*
|
||||
* \param rq The scheduler's run queue
|
||||
*/
|
||||
void stud_RR_wait(struct run_queue* rq) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Sets the state of `pid` to READY, if it exists, and moves it to the BACK
|
||||
* of the run_queue
|
||||
*
|
||||
* \param rq The scheduler's run queue
|
||||
* \param pid The process to be woken up
|
||||
*/
|
||||
void stud_RR_wake_up(struct run_queue* rq, int pid) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Event handler for RR
|
||||
*
|
||||
* \param rq The scheduler's run queue
|
||||
* \param event The event to be handled
|
||||
* \param pid Depending on `event`, the `pid` of the target process.
|
||||
* If the `event` doesn't need this, it is ignored.
|
||||
*/
|
||||
void stud_RR(struct run_queue* rq, enum events event, int pid) {
|
||||
switch(event) {
|
||||
case start: {
|
||||
stud_RR_start(rq, pid);
|
||||
break;
|
||||
}
|
||||
case terminate: {
|
||||
stud_RR_terminate(rq);
|
||||
break;
|
||||
}
|
||||
case clock_tick: {
|
||||
stud_RR_clock_tick(rq);
|
||||
break;
|
||||
}
|
||||
case wait: {
|
||||
stud_RR_wait(rq);
|
||||
break;
|
||||
}
|
||||
case wake_up: {
|
||||
stud_RR_wake_up(rq, pid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
sjf.c
Normal file
5
sjf.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include "sjf.h"
|
||||
|
||||
void sched_sjf(struct proc *list, int *schedule) {
|
||||
return;
|
||||
}
|
||||
Loading…
Reference in a new issue