OSMutex.o 100%

This commit is contained in:
Joshua Andrew 2023-07-10 22:16:04 -04:00
parent 2c94df2c88
commit 787916ee26
4 changed files with 152 additions and 11 deletions

View File

@ -149,11 +149,11 @@ ConfigMEM_ES1_0,OSMemory.o,os.a,true
RealMode,OSMemory.o,os.a,true
BATConfig,OSMemory.o,os.a,true
__OSInitMemoryProtection,OSMemory.o,os.a,true
OSInitMutex,OSMutex.o,os.a,false
OSLockMutex,OSMutex.o,os.a,false
OSUnlockMutex,OSMutex.o,os.a,false
__OSUnlockAllMutex,OSMutex.o,os.a,false
OSTryLockMutex,OSMutex.o,os.a,false
OSInitMutex,OSMutex.o,os.a,true
OSLockMutex,OSMutex.o,os.a,true
OSUnlockMutex,OSMutex.o,os.a,true
__OSUnlockAllMutex,OSMutex.o,os.a,true
OSTryLockMutex,OSMutex.o,os.a,true
__OSReboot,OSReboot.o,os.a,false
OSGetSaveRegion,OSReboot.o,os.a,false
OSRegisterShutdownFunction,OSReset.o,os.a,true

1 Symbol Name Object File Library Archive Matching
149 RealMode OSMemory.o os.a true
150 BATConfig OSMemory.o os.a true
151 __OSInitMemoryProtection OSMemory.o os.a true
152 OSInitMutex OSMutex.o os.a false true
153 OSLockMutex OSMutex.o os.a false true
154 OSUnlockMutex OSMutex.o os.a false true
155 __OSUnlockAllMutex OSMutex.o os.a false true
156 OSTryLockMutex OSMutex.o os.a false true
157 __OSReboot OSReboot.o os.a false
158 OSGetSaveRegion OSReboot.o os.a false
159 OSRegisterShutdownFunction OSReset.o os.a true

View File

@ -23,7 +23,7 @@
| OSLink.o | 100.0% | 1 / 1 | 100.0% | :white_check_mark:
| OSMessage.o | 0.0% | 0 / 4 | 0.0% | :x:
| OSMemory.o | 100.0% | 18 / 18 | 100.0% | :white_check_mark:
| OSMutex.o | 0.0% | 0 / 5 | 0.0% | :x:
| OSMutex.o | 100.0% | 5 / 5 | 100.0% | :white_check_mark:
| OSReboot.o | 0.0% | 0 / 2 | 0.0% | :x:
| OSReset.o | 7.744107744107744% | 2 / 14 | 14.285714285714285% | :eight_pointed_black_star:
| OSRtc.o | 100.0% | 9 / 9 | 100.0% | :white_check_mark:
@ -270,11 +270,11 @@
# OSMutex.o
| Symbol | Decompiled? |
| ------------- | ------------- |
| OSInitMutex | :x: |
| OSLockMutex | :x: |
| OSUnlockMutex | :x: |
| __OSUnlockAllMutex | :x: |
| OSTryLockMutex | :x: |
| OSInitMutex | :white_check_mark: |
| OSLockMutex | :white_check_mark: |
| OSUnlockMutex | :white_check_mark: |
| __OSUnlockAllMutex | :white_check_mark: |
| OSTryLockMutex | :white_check_mark: |
# OSReboot.o

View File

@ -126,6 +126,7 @@ void __OSInitMemoryProtection(void);
void __OSGetIOSRev(OSIOSRev *);
int __OSInitSTM(void);
void __OSInitNet(void);
void __OSPromoteThread(OSThread *, OSPriority);
extern void __RAS_OSDisableInterrupts_begin(void);
extern void __RAS_OSDisableInterrupts_end(void);

View File

@ -0,0 +1,140 @@
#include <revolution/os.h>
#define EnqueueTail(queue, mutex, link) \
do { \
OSMutex* __prev; \
\
__prev = (queue)->tail; \
if (__prev == NULL) \
(queue)->head = (mutex); \
else \
__prev->link.next = (mutex); \
(mutex)->link.prev = __prev; \
(mutex)->link.next = NULL; \
(queue)->tail = (mutex); \
} while (0)
#define DequeueItem(queue, mutex, link) \
do { \
OSMutex* __next; \
OSMutex* __prev; \
\
__next = (mutex)->link.next; \
__prev = (mutex)->link.prev; \
\
if (__next == NULL) \
(queue)->tail = __prev; \
else \
__next->link.prev = __prev; \
\
if (__prev == NULL) \
(queue)->head = __next; \
else \
__prev->link.next = __next; \
} while (0)
#define DequeueHead(queue, mutex, link) \
do { \
OSMutex* __next; \
\
(mutex) = (queue)->head; \
__next = (mutex)->link.next; \
if (__next == NULL) \
(queue)->tail = NULL; \
else \
__next->link.prev = NULL; \
(queue)->head = __next; \
} while (0)
void OSInitMutex(OSMutex* mutex) {
OSInitThreadQueue(&mutex->queue);
mutex->thread = NULL;
mutex->count = 0;
}
void OSLockMutex(OSMutex* mutex) {
BOOL enabled;
OSThread* currentThread, *ownerThread;
enabled = OSDisableInterrupts();
currentThread = OSGetCurrentThread();
for (;;) {
ownerThread = ((volatile OSMutex*)mutex)->thread;
if (ownerThread == NULL) {
mutex->thread = currentThread;
mutex->count++;
EnqueueTail(&currentThread->queueMutex, mutex, link);
break;
}
else if (ownerThread == currentThread) {
mutex->count++;
break;
}
else {
currentThread->mutex = mutex;
__OSPromoteThread(mutex->thread, currentThread->priority);
OSSleepThread(&mutex->queue);
currentThread->mutex = NULL;
}
}
OSRestoreInterrupts(enabled);
}
void OSUnlockMutex(OSMutex* mutex) {
BOOL enabled;
OSThread* currentThread;
enabled = OSDisableInterrupts();
currentThread = OSGetCurrentThread();
if (mutex->thread == currentThread && --mutex->count == 0) {
DequeueItem(&currentThread->queueMutex, mutex, link);
mutex->thread = NULL;
if (currentThread->priority < currentThread->base) {
currentThread->priority = __OSGetEffectivePriority(currentThread);
}
OSWakeupThread(&mutex->queue);
}
OSRestoreInterrupts(enabled);
}
void __OSUnlockAllMutex(OSThread* thread) {
OSMutex* mutex;
while (thread->queueMutex.head) {
DequeueHead(&thread->queueMutex, mutex, link);
ASSERT(mutex->thread == thread);
mutex->count = 0;
mutex->thread = NULL;
OSWakeupThread(&mutex->queue);
}
}
BOOL OSTryLockMutex(OSMutex* mutex) {
BOOL enabled, locked;
OSThread* currentThread;
enabled = OSDisableInterrupts();
currentThread = OSGetCurrentThread();
if (mutex->thread == NULL) {
mutex->thread = currentThread;
mutex->count++;
EnqueueTail(&currentThread->queueMutex, mutex, link);
locked = TRUE;
}
else if (mutex->thread == currentThread) {
mutex->count++;
locked = TRUE;
}
else {
locked = FALSE;
}
OSRestoreInterrupts(enabled);
return locked;
}