aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/globals.h3
-rw-r--r--include/lib/queue.h32
-rw-r--r--include/sys/schedule.h25
3 files changed, 38 insertions, 22 deletions
diff --git a/include/globals.h b/include/globals.h
index ce98c97..24bd4f5 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -15,9 +15,8 @@ extern unsigned long stimeh;
extern struct Scheduler scheduler;
extern struct Thread usrloopthread;
extern unsigned int gwidth, gheight, gpitch, gisrgb;
-extern unsigned char thread_table[MAX_THREADS];
extern struct Thread threads[MAX_THREADS];
-extern struct ThreadEntry thread_entries[MAX_THREADS];
+extern struct Entry thread_entries[MAX_THREADS];
extern unsigned long mutex_table[MAX_MUTEXS];
extern struct Mutex mutexs[MAX_MUTEXS];
#endif
diff --git a/include/lib/queue.h b/include/lib/queue.h
new file mode 100644
index 0000000..5e57613
--- /dev/null
+++ b/include/lib/queue.h
@@ -0,0 +1,32 @@
+#ifndef LIB_QUEUE_H
+#define LIB_QUEUE_H
+
+enum EntryType {
+ VALUE_ENTRY = 0,
+ START_ENTRY = 1,
+ END_ENTRY = 2,
+};
+
+struct Entry {
+ void* value;
+ struct Entry* next;
+ unsigned long entry_type;
+};
+
+struct Queue {
+ struct Entry start;
+ struct Entry end;
+};
+
+// Add to end of queue
+void push_to_queue(struct Entry* e, struct Queue* q);
+// Add to beginning of queue
+void prepend_to_queue(struct Entry* e, struct Queue* q);
+// Remove from beginning of queue
+struct Entry* pop_from_queue(struct Queue* q);
+// Remove the entry after this one from its queue
+struct Entry* remove_next_from_queue(struct Entry* e);
+// Find an entry in a queue
+struct Entry* find_value(void* value, struct Queue* q);
+
+#endif
diff --git a/include/sys/schedule.h b/include/sys/schedule.h
index d0d938c..18b2f7f 100644
--- a/include/sys/schedule.h
+++ b/include/sys/schedule.h
@@ -1,5 +1,6 @@
#ifndef SYS_SCHEDULE_H
#define SYS_SCHEDULE_H
+#include <lib/queue.h>
#define TQUEUE_MAX 0x800
#define STACK_SIZE 0x4000
@@ -13,12 +14,6 @@ enum ThreadStatus {
THREAD_SWAIT = 2,
};
-enum EntryTypes {
- THREAD_ENTRY = 0,
- START_ENTRY = 1,
- END_ENTRY = 2,
-};
-
struct Thread {
void* pc;
void* sp; // Store r0-r12,lr on stack
@@ -35,22 +30,12 @@ struct Thread {
unsigned short s_reserved;
};
-struct ThreadEntry {
- struct Thread* thread;
- struct ThreadEntry* next;
- unsigned long entry_type;
-};
-
-struct ThreadQueue {
- struct ThreadEntry start;
- struct ThreadEntry end;
-};
-
struct Scheduler {
struct Thread* rthread;
- struct ThreadQueue ready[PRIORITIES];
- struct ThreadQueue mwait[PRIORITIES];
- struct ThreadQueue swait[PRIORITIES];
+ struct Queue ready[PRIORITIES];
+ struct Queue mwait[PRIORITIES];
+ struct Queue swait[PRIORITIES];
+ struct Queue free_threads;
};
void init_scheduler(void);