Massive backlog of changes

This commit is contained in:
2022-06-15 15:59:31 -05:00
parent c962a83ff0
commit a52f06f81e
49 changed files with 1855 additions and 1083 deletions

View File

@@ -1,11 +1,31 @@
#pragma once
#include "pageallocator.h"
#include "kernel.h"
#include <stddef.h>
/**
* @brief An pair consisting of a priority and a pointer to be stored in
* a priority queue.
*
*/
struct priority_queue_node_t
{
/**
* @brief A pointer to some user-defined object.
*
*/
void *value;
/**
* @brief The priority of the associated object. Only the object with the
* lowest priority is directly accessible from a priority queue.
*
*/
int priority;
};
/**
* @brief
* @brief A priority queue. Each object in the queue contains a priority and
* a pointer to some user-defined value, and a priority. Operations on the
* queue consist of insertion and deletion of objects, and extraction of the
* object with the lowest priority.
*
*/
struct priority_queue_t
@@ -14,45 +34,59 @@ struct priority_queue_t
* @brief A pointer to the heap described by this structure.
*
*/
struct process_t **heap;
struct priority_queue_node_t *heap;
/**
* @brief The current number of elements stored in the heap.
*
*/
size_t size;
int size;
/**
* @brief The maximum number of elements that the heap can currently hold.
*
*/
size_t capacity;
int capacity;
};
int construct_priority_queue(struct priority_queue_t *queue, struct page_stack_t *page_stack);
/**
* @brief
* @brief Initializes the given queue struct.
*
* The queue's underlying heap is allocated
*
* @param queue
* @return struct process_t*
*/
struct process_t *extract_min(struct priority_queue_t *queue);
/**
* @brief
*
* @param queue
* @param process
* @return int
*/
int queue_insert(struct priority_queue_t *queue, struct process_t *process);
int construct_priority_queue(struct priority_queue_t *queue, int capacity);
/**
* @brief
* @brief Extracts the object with the lowest priority off the given queue.
*
* The object is removed from the queue, and a pointer to its userdata is
* returned. If the queue is empty, this function returns NULL and the queue
* is unaffected. If multiple objects with the same priority are stored on the
* queue, this function will extract the object lest-recently inserted.
*
* @param queue
* @param process
* @return void*
*/
void *extract_min(struct priority_queue_t *queue);
/**
* @brief Inserts a new object onto the queue.
*
* @param queue
* @param value
* @param priority
* @return int
*/
int queue_remove(struct priority_queue_t *queue, struct process_t *process);
int queue_insert(struct priority_queue_t *queue, void *value, int priority);
/**
* @brief Removes the object with a matching value from the queue.
*
* @param queue
* @param value
* @return int
*/
int queue_remove(struct priority_queue_t *queue, void *value);