sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

osDestroyThread.c (1088B)


      1 #include "libultra_internal.h"
      2 
      3 void osDestroyThread(OSThread *thread) {
      4     register s32 int_disabled;
      5     register OSThread *s1;
      6     register OSThread *s2;
      7 
      8     int_disabled = __osDisableInt();
      9 
     10     if (thread == NULL) {
     11         thread = __osRunningThread;
     12     } else if (thread->state != OS_STATE_STOPPED) {
     13         __osDequeueThread(thread->queue, thread);
     14     }
     15 
     16     if (__osActiveQueue == thread) {
     17         __osActiveQueue = __osActiveQueue->tlnext;
     18     } else {
     19         s1 = __osActiveQueue;
     20 #ifdef VERSION_CN
     21         while (s1->priority != -1) {
     22             s2 = s1->tlnext;
     23             if (s2 == thread) {
     24                 s1->tlnext = thread->tlnext;
     25                 break;
     26             }
     27             s1 = s2;
     28         }
     29 #else
     30         s2 = s1->tlnext;
     31         while (s2 != NULL) {
     32             if (s2 == thread) {
     33                 s1->tlnext = thread->tlnext;
     34                 break;
     35             }
     36             s1 = s2;
     37             s2 = s1->tlnext;
     38         }
     39 #endif
     40     }
     41 
     42     if (thread == __osRunningThread) {
     43         __osDispatchThread();
     44     }
     45 
     46     __osRestoreInt(int_disabled);
     47 }