BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 843a5201164f3cff1b57989ec7625ccf8bd05d5b

// Related

Nucleus

Barry Private TaskQueue structure 843a520 (3 years, 3 months ago)
diff --git a/include/nucleus/task.h b/include/nucleus/task.h
index 547fabc..f017d11 100644
--- a/include/nucleus/task.h
+++ b/include/nucleus/task.h
@@ -39,12 +39,6 @@ struct Task {
 	Task *next;
 };
 
-/* Structure for a Task Queue */
-struct TaskQueue {
-	Object obj;
-	Task *start, *end;
-};
-
 extern ObjectType taskType;
 extern ObjectType taskQueueType;
 
@@ -58,5 +52,6 @@ pid_t clone(int flags);
 void add_to_queue(TaskQueue *queue, Task *task);
 void remove_from_queue(TaskQueue *queue, Task *task);
 Task *pop_from_queue(TaskQueue *queue);
+size_t tasks_in_queue(TaskQueue *queue);
 
 #endif
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;