From a61201b8047ebe278cfb281723a4bf6c82556472 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Thu, 6 Jan 2022 15:51:48 -0800 Subject: Scheduling --- src/util/mutex.c | 22 ++++++++++++++++++++-- src/util/status.c | 28 +++++++++++++++++----------- 2 files changed, 37 insertions(+), 13 deletions(-) (limited to 'src/util') diff --git a/src/util/mutex.c b/src/util/mutex.c index ade0be3..de7a515 100644 --- a/src/util/mutex.c +++ b/src/util/mutex.c @@ -1,13 +1,23 @@ #include #include +#include #include unsigned char lock_mutex(struct Mutex* m, unsigned long pid) { if (m->pid == NULL_PID) { - atm_lock(pid, &m->pid); + // Use currently running thread's PID if no pid given + if (pid == 0) { + struct Thread* thread = scheduler.rthread_ll->data; + atm_lock(thread->data.pid, &m->pid); + } else { + atm_lock(pid, &m->pid); + } return 0; } + struct Thread* thread = scheduler.rthread_ll->data; + thread->data.status = THREAD_WAITING_FOR_MUTEX; + thread->data.mutex_waiting = m; return 1; } @@ -16,7 +26,15 @@ unsigned char lock_mutex(struct Mutex* m, unsigned long pid) // mutex's pid lock unsigned char release_mutex(struct Mutex* m, unsigned long pid) { - if (m->pid == pid) { + // Use current thread's PID if no pid + if (pid == 0) { + struct Thread* thread = scheduler.rthread_ll->data; + if (m->pid == thread->data.pid) { + atm_release(&m->pid); + return 0; + } + } + else if (m->pid == pid) { atm_release(&m->pid); return 0; } diff --git a/src/util/status.c b/src/util/status.c index f59ede6..be19287 100644 --- a/src/util/status.c +++ b/src/util/status.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -129,19 +130,24 @@ void status(void) write_char(&g_Drawer, ' '); g_Drawer.x = 0; g_Drawer.y = 9; - /* - struct Q* q = scheduler.tasks->next; - while (q != 0) { - struct Task* t = q->data; - write_hex32(&g_Drawer, (unsigned long)t->task); - write_char(&g_Drawer, ' '); - q = q->next; - } - write_char(&g_Drawer, '\n'); - */ - unsigned long sp = (unsigned long)getsp(); + unsigned long sp = (unsigned long)getsvcstack(); + write_hex32(&g_Drawer, sp); + write_char(&g_Drawer, ' '); + sp = (unsigned long)getirqstack(); write_hex32(&g_Drawer, sp); + write_char(&g_Drawer, ' '); + sp = (unsigned long)getfiqstack(); + write_hex32(&g_Drawer, sp); + write_char(&g_Drawer, '\n'); + for(unsigned long i = 1; i <= 14; i++) { + write_hex32(&g_Drawer, *(unsigned long*)(0x4000 - i*4)); + if(i % 6 == 0) { + write_char(&g_Drawer, '\n'); + } else { + write_char(&g_Drawer, ' '); + } + } g_Drawer.x = x; g_Drawer.y = y; -- cgit v1.2.1