Nucleus
Barry Private TaskQueue structure 843a520 (3 years, 3 months ago)
diff --git a/task/queue.c b/task/queue.c
index 071a1fe..7d82c87 100644
--- a/task/queue.c
+++ b/task/queue.c
@@ -8,6 +8,13 @@
#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 *);
@@ -45,6 +52,7 @@ add_to_queue(TaskQueue *queue, Task *task)
queue->end->next = get(task);
queue->end = task;
task->next = NULL;
+ queue->tasks++;
unlock(queue);
}
@@ -78,7 +86,7 @@ found:
task->next = NULL;
put(task);
-
+ queue->tasks--;
unlock(queue);
}
@@ -92,3 +100,10 @@ pop_from_queue(TaskQueue *queue)
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 cad926d..06012ae 100644
--- a/task/scheduler.c
+++ b/task/scheduler.c
@@ -46,7 +46,7 @@ highest_priority_queue(void)
{
enum Priority p;
for (p = PRIORITY_COUNT - 1; p > 0; p--) {
- if (readyQueue[p]->start)
+ if (tasks_in_queue(readyQueue[p]))
return readyQueue[p];
}
return NULL;