mirror of https://github.com/zeldaret/tp.git
212 lines
8.4 KiB
C
212 lines
8.4 KiB
C
//
|
|
// Generated By: dol2asm
|
|
// Translation Unit: OSMutex
|
|
//
|
|
|
|
#include "dolphin/os/OSMutex.h"
|
|
#include "dol2asm.h"
|
|
#include "dolphin/os/OS.h"
|
|
|
|
#define PushTail(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 PopHead(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)
|
|
|
|
#define PopItem(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)
|
|
|
|
//
|
|
// Declarations:
|
|
//
|
|
|
|
/* 8033F008-8033F040 339948 0038+00 0/0 12/12 0/0 .text OSInitMutex */
|
|
void OSInitMutex(OSMutex* mutex) {
|
|
OSInitThreadQueue(&mutex->queue);
|
|
mutex->thread = 0;
|
|
mutex->count = 0;
|
|
}
|
|
|
|
/* 8033F040-8033F11C 339980 00DC+00 1/1 62/62 0/0 .text OSLockMutex */
|
|
// needs compiler epilogue patch
|
|
#ifdef NONMATCHING
|
|
void OSLockMutex(OSMutex* mutex) {
|
|
BOOL enabled = OSDisableInterrupts();
|
|
OSThread* currentThread = OSGetCurrentThread();
|
|
OSThread* ownerThread;
|
|
|
|
while (TRUE) {
|
|
ownerThread = ((OSMutex*)mutex)->thread;
|
|
if (ownerThread == 0) {
|
|
mutex->thread = currentThread;
|
|
mutex->count++;
|
|
PushTail(¤tThread->owned_mutexes, mutex, link);
|
|
break;
|
|
} else if (ownerThread == currentThread) {
|
|
mutex->count++;
|
|
break;
|
|
} else {
|
|
currentThread->mutex = mutex;
|
|
__OSPromoteThread(mutex->thread, currentThread->effective_priority);
|
|
OSSleepThread(&mutex->queue);
|
|
currentThread->mutex = 0;
|
|
}
|
|
}
|
|
OSRestoreInterrupts(enabled);
|
|
}
|
|
#else
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void OSLockMutex(OSMutex* mutex) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/OSLockMutex.s"
|
|
}
|
|
#pragma pop
|
|
#endif
|
|
|
|
/* 8033F11C-8033F1E4 339A5C 00C8+00 0/0 71/71 0/0 .text OSUnlockMutex */
|
|
#ifdef NONMATCHING
|
|
void OSUnlockMutex(OSMutex* mutex) {
|
|
BOOL enabled = OSDisableInterrupts();
|
|
OSThread* currentThread = OSGetCurrentThread();
|
|
|
|
if (mutex->thread == currentThread && --mutex->count == 0) {
|
|
PopItem(¤tThread->owned_mutexes, mutex, link);
|
|
mutex->thread = NULL;
|
|
if (currentThread->effective_priority < currentThread->base_priority) {
|
|
currentThread->effective_priority = __OSGetEffectivePriority(currentThread);
|
|
}
|
|
|
|
OSWakeupThread(&mutex->queue);
|
|
}
|
|
OSRestoreInterrupts(enabled);
|
|
}
|
|
#else
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void OSUnlockMutex(OSMutex* mutex) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/OSUnlockMutex.s"
|
|
}
|
|
#pragma pop
|
|
#endif
|
|
|
|
/* 8033F1E4-8033F254 339B24 0070+00 0/0 2/2 0/0 .text __OSUnlockAllMutex */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void __OSUnlockAllMutex(OSThread* thread) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/__OSUnlockAllMutex.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033F254-8033F310 339B94 00BC+00 0/0 9/9 0/0 .text OSTryLockMutex */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm s32 OSTryLockMutex(OSMutex* mutex) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/OSTryLockMutex.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033F310-8033F330 339C50 0020+00 0/0 1/1 0/0 .text OSInitCond */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void OSInitCond(OSCond* cond) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/OSInitCond.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033F330-8033F404 339C70 00D4+00 0/0 1/1 0/0 .text OSWaitCond */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void OSWaitCond(OSCond* cond, OSMutex* mutex) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/OSWaitCond.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033F404-8033F424 339D44 0020+00 0/0 5/5 0/0 .text OSSignalCond */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm void OSSignalCond(OSCond* con) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/OSSignalCond.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033F424-8033F524 339D64 0100+00 1/1 0/0 0/0 .text __OSCheckMutex */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm s32 __OSCheckMutex(OSThread* thread) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/__OSCheckMutex.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033F524-8033F55C 339E64 0038+00 0/0 1/1 0/0 .text __OSCheckDeadLock */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm BOOL __OSCheckDeadLock(OSThread* thread) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/__OSCheckDeadLock.s"
|
|
}
|
|
#pragma pop
|
|
|
|
/* 8033F55C-8033F5D0 339E9C 0074+00 0/0 1/1 0/0 .text __OSCheckMutexes */
|
|
#pragma push
|
|
#pragma optimization_level 0
|
|
#pragma optimizewithasm off
|
|
asm BOOL __OSCheckMutexes(OSThread* thread) {
|
|
nofralloc
|
|
#include "asm/dolphin/os/OSMutex/__OSCheckMutexes.s"
|
|
}
|
|
#pragma pop
|