mirror of
https://github.com/SMGCommunity/Petari.git
synced 2025-02-25 16:40:50 +00:00
OSMutex.o
100%
This commit is contained in:
parent
2c94df2c88
commit
787916ee26
@ -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
|
||||
|
|
@ -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
|
||||
|
@ -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);
|
||||
|
140
libs/RVL_SDK/source/revolution/os/OSMutex.c
Normal file
140
libs/RVL_SDK/source/revolution/os/OSMutex.c
Normal 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(¤tThread->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(¤tThread->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(¤tThread->queueMutex, mutex, link);
|
||||
locked = TRUE;
|
||||
}
|
||||
else if (mutex->thread == currentThread) {
|
||||
mutex->count++;
|
||||
locked = TRUE;
|
||||
}
|
||||
else {
|
||||
locked = FALSE;
|
||||
}
|
||||
|
||||
OSRestoreInterrupts(enabled);
|
||||
return locked;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user