BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 843a5201164f3cff1b57989ec7625ccf8bd05d5b / task / queue.c

// Related

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;
+}