BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 4d3c382801026ca46da937de6d7261f1f6805d9e / task

// Related

Nucleus

Barry Object Lists + replacing Task Queues 4d3c382 (3 years, 3 months ago)
diff --git a/task/clone.c b/task/clone.c
index 5e425fa..41cbc48 100644
--- a/task/clone.c
+++ b/task/clone.c
@@ -6,7 +6,7 @@
 #include <sys/types.h>
 #include <nucleus/task.h>
 
-extern TaskQueue *readyQueue[];
+extern ObjectList *readyQueue[];
 
 /* Clone a task */
 pid_t
@@ -24,7 +24,7 @@ clone(int flags)
 	child->eip = (uintptr_t) &&end;
 	asm volatile("mov %%esp, %0" : "=r" (child->esp));
 	asm volatile("mov %%ebp, %0" : "=r" (child->ebp));
-	add_to_queue(readyQueue[child->priority], child);
+	add(readyQueue[child->priority], child);
 	tid = child->tid;
 	put(child);
 end:
diff --git a/task/queue.c b/task/queue.c
deleted file mode 100644
index 7d82c87..0000000
--- a/task/queue.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * This file implements the Task Queue object and contains all the functions for
- * dealing with them.  A Task Queue holds a reference to every Task it contains.
- * There is a single reference per task for the entire queue, and tasks do not
- * hold references to their neighbour, nor the queue its end.
- */
-
-#include <nucleus/object.h>
-#include <nucleus/task.h>
-
-/* Structure for a Task Queue */
-struct TaskQueue {
-	Object obj;
-	Task *start, *end;
-	size_t tasks;
-};
-
-static void *task_queue_new(void);
-static void task_queue_delete(Object *);
-
-/* Task Queue object type */
-ObjectType taskQueueType = {
-	.new = task_queue_new,
-	.delete = task_queue_delete,
-};
-
-/* Create a new Task Queue */
-static void *
-task_queue_new(void)
-{
-	TaskQueue *queue = kmalloc(sizeof(TaskQueue));
-}
-
-/* Destroy a Task Queue */
-static void
-task_queue_delete(Object *obj)
-{
-	TaskQueue *queue = (void *) obj;
-	while (queue->start)
-		put(pop_from_queue(queue));
-	kfree(queue);
-}
-
-/* Add a Task to a Task Queue */
-void
-add_to_queue(TaskQueue *queue, Task *task)
-{
-	lock(queue);
-	if (!queue->start)
-		queue->start = get(task);
-	else
-		queue->end->next = get(task);
-	queue->end = task;
-	task->next = NULL;
-	queue->tasks++;
-	unlock(queue);
-}
-
-/* Remove a Task from a Task Queue */
-void
-remove_from_queue(TaskQueue *queue, Task *task)
-{
-	lock(queue);
-
-	/* Start of queue */
-	if (queue->start == task) {
-		queue->start = task->next;
-		goto found;
-	}
-
-	/* Search */
-	Task *prev;
-	for (prev = queue->start; prev->next; prev = prev->next)
-		if (prev->next == task)
-			break;
-	if (!prev->next) {
-		unlock(queue);
-		return;
-	}
-
-	prev->next = task->next;
-
-found:
-	if (queue->end == task)
-		queue->end = NULL;
-
-	task->next = NULL;
-	put(task);
-	queue->tasks--;
-	unlock(queue);
-}
-
-/* Remove the first Task from a Task Queue */
-Task *
-pop_from_queue(TaskQueue *queue)
-{
-	lock(queue);
-	Task *head = get(queue->start);
-	remove_from_queue(queue, queue->start);
-	unlock(queue);
-	return head;
-}
-
-/* Count the tasks in a queue */
-size_t
-tasks_in_queue(TaskQueue *queue)
-{
-	return queue->tasks;
-}
diff --git a/task/scheduler.c b/task/scheduler.c
index 06012ae..7b08fc2 100644
--- a/task/scheduler.c
+++ b/task/scheduler.c
@@ -11,7 +11,7 @@
 
 #define PRIORITY_COUNT 6
 
-TaskQueue *readyQueue[PRIORITY_COUNT];
+ObjectList *readyQueue[PRIORITY_COUNT];
 
 /* Switch to a task */
 static void
@@ -41,12 +41,12 @@ end:
 }
 
 /* Find the next schedulable ready queue */
-static TaskQueue *
+static ObjectList *
 highest_priority_queue(void)
 {
 	enum Priority p;
 	for (p = PRIORITY_COUNT - 1; p > 0; p--) {
-		if (tasks_in_queue(readyQueue[p]))
+		if (count(readyQueue[p]))
 			return readyQueue[p];
 	}
 	return NULL;
@@ -57,15 +57,15 @@ void
 schedule(void)
 {
 	Task *task = current;
-	TaskQueue *queue = highest_priority_queue();
+	ObjectList *queue = highest_priority_queue();
 
 	/* Next schedulable task */
 	if (queue) {
-		task = pop_from_queue(queue);
+		task = pop_from_start(queue);
 		task->state = RUNNING;
 		if (current->state == RUNNING) {
 			current->state = READY;
-			add_to_queue(readyQueue[current->priority], current);
+			add(readyQueue[current->priority], current);
 		}
 		switch_to_task(task);
 	/* Idle */
@@ -76,7 +76,7 @@ schedule(void)
 			asm volatile("hlt");
 		asm volatile("cli");
 		current = task;
-		task = pop_from_queue(queue);
+		task = pop_from_start(queue);
 		task->state = RUNNING;
 		switch_to_task(task);
 	}
@@ -88,5 +88,5 @@ init_scheduler(void)
 {
 	enum Priority p;
 	for (p = 0; p < PRIORITY_COUNT; p++)
-		readyQueue[p] = new(&taskQueueType);
+		readyQueue[p] = create_list(&taskType);
 }
diff --git a/task/task.c b/task/task.c
index 9fafc6f..8b64df0 100644
--- a/task/task.c
+++ b/task/task.c
@@ -14,34 +14,25 @@
 void init_scheduler(void);
 void timer_handler(struct InterruptFrame *frame);
 
-static void *task_new(void);
-static void task_delete(Object *);
+static void task_new(Object *);
 
 /* Task object type */
 ObjectType taskType = {
+	.size = sizeof(Task),
 	.new = task_new,
-	.delete = task_delete,
 };
 
 Task *currentTask[MAX_CPUS];
 pid_t nextTid = 1;
 
 /* Create a new Task */
-static void *
-task_new(void)
+static void
+task_new(Object *obj)
 {
-	Task *task = kmalloc(sizeof(Task));
+	Task *task = (void *) obj;
 	task->tid = nextTid++;
 	task->priority = NORMAL;
 	task->state = READY;
-	return task;
-}
-
-/* Destroy a Task */
-static void
-task_delete(Object *obj)
-{
-	kfree(obj);
 }
 
 extern char stackTop[];