BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / bb0cb7718204df7c0cbaf87484b1def3c4b2880f / include / nucleus / task.h

// Related

Nucleus

Barry Per-CPU Scheduler bb0cb77 (3 years, 2 months ago)
diff --git a/include/nucleus/task.h b/include/nucleus/task.h
index 80a2a71..6212be0 100644
--- a/include/nucleus/task.h
+++ b/include/nucleus/task.h
@@ -18,6 +18,7 @@ enum Priority {
 	HIGH,
 	HIGHEST,
 };
+#define PRIORITY_COUNT 6
 
 /* Task states */
 enum State {
@@ -34,11 +35,11 @@ struct Task {
 	uid_t uid, euid, suid;
 	gid_t gid, egid, sgid;
 	int status;
-	enum Priority priority;
-	enum State state;
-	uint32_t inCriticalSection;
 	uint32_t inSyscall;
 
+	Scheduler *scheduler;
+	enum Priority priority;
+	enum State state;
 	uintptr_t esi, edi, ebx;
 	uintptr_t esp, ebp, eip;
 	page_dir_t pageDir;
@@ -55,9 +56,20 @@ struct Task {
 	Signals *signals;
 };
 
-#define current cpu->task
+/* Structure for a Scheduler */
+struct Scheduler {
+	Object obj;
+	Processor *cpu;
+	Task *task;
+	ObjectList *queue[PRIORITY_COUNT];
+	uint32_t timeslice;
+	size_t tasks;
+};
+
+#define current cpu->scheduler->task
 
 extern ObjectType taskType;
+extern ObjectType schedulerType;
 extern ObjectType signalsType;
 
 /* Check if super-user */
@@ -67,24 +79,11 @@ super_user(void)
 	return (current->euid == 0);
 }
 
-/* Enter a critical section */
-static inline void
-enter_critical_section(void)
-{
-	__atomic_add_fetch(&current->inCriticalSection, 1, __ATOMIC_RELAXED);
-}
-/* Exit a critical section */
-static inline void
-exit_critical_section(void)
-{
-	__atomic_sub_fetch(&current->inCriticalSection, 1, __ATOMIC_RELAXED);
-}
-
 /* Enter system call context */
 static inline void
-enter_syscall_context(uint32_t syscall)
+enter_syscall_context(void)
 {
-	current->inSyscall = syscall;
+	current->inSyscall = 1;
 }
 /* Exit system call context */
 static inline uint32_t
@@ -96,6 +95,7 @@ exit_syscall_context(void)
 }
 
 void init_tasking(void);
+void enqueue_task(Task *task);
 void block_task(enum State reason, ObjectList *list);
 void unblock_task(Task *task);
 Task *find_task(pid_t tid);