"THREAD_STAT_ACTIVE",
"THREAD_STAT_SLEEPING",
"THREAD_STAT_MUTEXSLEEP",
+ "THREAD_STAT_RWLOCKSLEEP",
"THREAD_STAT_SEMAPHORESLEEP",
"THREAD_STAT_QUEUESLEEP",
"THREAD_STAT_EVENTSLEEP",
extern tThread *Threads_CloneTCB(Uint Flags);
extern tThread *Threads_CloneThreadZero(void);
+extern void Threads_int_WaitForStatusEnd(enum eThreadStatus Status);
extern void Semaphore_ForceWake(tThread *Thread);
#endif
SHORTREL( &glThreadListLock );
SHORTREL( &Mutex->Protector );
- while(us->Status == THREAD_STAT_MUTEXSLEEP) Threads_Yield();
+ Threads_int_WaitForStatusEnd(THREAD_STAT_MUTEXSLEEP);
// We're only woken when we get the lock
us->WaitPointer = NULL;
}
SHORTREL( &glThreadListLock );
SHORTREL( &Lock->Protector );
- while(us->Status == THREAD_STAT_RWLOCKSLEEP) Threads_Yield();
+ Threads_int_WaitForStatusEnd(THREAD_STAT_RWLOCKSLEEP);
// We're only woken when we get the lock
// TODO: Handle when this isn't the case
us->WaitPointer = NULL;
SHORTREL( &glThreadListLock );
SHORTREL( &Lock->Protector );
- while(us->Status == THREAD_STAT_RWLOCKSLEEP) Threads_Yield();
+ Threads_int_WaitForStatusEnd(THREAD_STAT_RWLOCKSLEEP);
us->WaitPointer = NULL;
}
else
SHORTREL( &Sem->Protector ); // Release first to make sure it is released
SHORTREL( &glThreadListLock );
// Sleep until woken (either by getting what we need, or a timer event)
- while( us->Status == THREAD_STAT_SEMAPHORESLEEP )
- {
- Threads_Yield();
- if(us->Status == THREAD_STAT_SEMAPHORESLEEP)
- Log_Warning("Threads", "Semaphore %p %s:%s re-schedulued while asleep",
- Sem, Sem->ModName, Sem->Name);
- }
+ Threads_int_WaitForStatusEnd( THREAD_STAT_SEMAPHORESLEEP );
+ // We're only woken when there's something avaliable (or a signal arrives)
#if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG
Log("Semaphore %p %s:%s woken", Sem, Sem->ModName, Sem->Name);
#endif
- // We're only woken when there's something avaliable (or a signal arrives)
us->WaitPointer = NULL;
taken = us->RetStatus;
SHORTREL( &glThreadListLock );
SHORTREL( &Sem->Protector );
- while(us->Status == THREAD_STAT_SEMAPHORESLEEP) Threads_Yield();
+ Threads_int_WaitForStatusEnd(THREAD_STAT_SEMAPHORESLEEP);
// We're only woken when there's something avaliable
us->WaitPointer = NULL;
Proc_Reschedule();
}
+/**
+ * \breif Wait for the thread status to not be a specified value
+ */
+void Threads_int_WaitForStatusEnd(enum eThreadStatus Status)
+{
+ tThread *us = Proc_GetCurThread();
+ ASSERT(Status != THREAD_STAT_ACTIVE);
+ ASSERT(Status != THREAD_STAT_DEAD);
+ while( us->Status == Status )
+ {
+ Proc_Reschedule();
+ if( us->Status == Status )
+ Debug("Thread %p(%i %s) rescheduled while in %s state", casTHREAD_STAT[Status]);
+ }
+}
+
/**
* \fn void Threads_Sleep(void)
* \brief Take the current process off the run queue
// Release Spinlock
SHORTREL( &glThreadListLock );
-
- while(cur->Status != THREAD_STAT_ACTIVE) {
- Proc_Reschedule();
- if( cur->Status != THREAD_STAT_ACTIVE )
- Log("%i - Huh? why am I up? zzzz...", cur->TID);
- }
+ Threads_int_WaitForStatusEnd(THREAD_STAT_SLEEPING);
}