diff --git a/Makefile b/Makefile index f7076323..9e60da56 100644 --- a/Makefile +++ b/Makefile @@ -198,7 +198,7 @@ COMMON_DEFINES := -D_MIPS_SZLONG=32 GBI_DEFINES := -DF3DEX_GBI RELEASE_DEFINES := -DNDEBUG -D_FINALROM AS_DEFINES := -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_ULTRA64 -C_DEFINES := -DLANGUAGE_C -D_LANGUAGE_C +C_DEFINES := -DLANGUAGE_C -D_LANGUAGE_C -DBUILD_VERSION=VERSION_H ENDIAN := -EB OPTFLAGS := -O2 -g3 @@ -274,6 +274,7 @@ build/src/libultra/libc/ll.o: OPTFLAGS := -O1 -g0 build/src/libultra/libc/ll.o: MIPS_VERSION := -mips3 -32 build/src/libultra/os/createmesgqueue.o: OPTFLAGS := -O1 -g0 +build/src/libultra/os/destroythread.o: OPTFLAGS := -O1 -g0 build/src/libultra/os/getactivequeue.o: OPTFLAGS := -O1 -g0 build/src/libultra/os/stopthread.o: OPTFLAGS := -O1 -g0 diff --git a/src/libultra/os/destroythread.c b/src/libultra/os/destroythread.c index 9fa2e0ee..a0d48d3b 100644 --- a/src/libultra/os/destroythread.c +++ b/src/libultra/os/destroythread.c @@ -1,3 +1,55 @@ -#include "common.h" +#include "PR/os_internal.h" +#include "osint.h" +#include "PR/os_version.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/destroythread/osDestroyThread.s") +// this is not supposed to be here, but the def check below is broken I guess. +#ifdef __sgi +#define __GNUC__ 0 +#endif + +void osDestroyThread(OSThread* t) { + register u32 saveMask; + register OSThread* pred; + register OSThread* succ; + + saveMask = __osDisableInt(); + + if (t == NULL) { + t = __osRunningThread; + } else if (t->state != OS_STATE_STOPPED) { + __osDequeueThread(t->queue, t); + } + + if (__osActiveQueue == t) { + __osActiveQueue = __osActiveQueue->tlnext; + } else { +#if BUILD_VERSION >= VERSION_J || !defined(__GNUC__) + pred = __osActiveQueue; + while (pred->priority != -1) { + succ = pred->tlnext; + if (succ == t) { + pred->tlnext = t->tlnext; + break; + } + pred = succ; + } +#else + pred = __osActiveQueue; + succ = pred->tlnext; + while (succ != NULL) { + if (succ == t) { + pred->tlnext = t->tlnext; + break; + } + pred = succ; + succ = pred->tlnext; + } +#endif + } + + if (t == __osRunningThread) { + __osDispatchThread(); + } + + __osRestoreInt(saveMask); +}