+ * \brief Wake a thread given the TID
+ * \param TID Thread ID to wake
+ * \return Boolean Faulure (errno)
+ */
+int Threads_WakeTID(tTID TID)
+{
+ tThread *thread = Threads_GetThread(TID);
+ int ret;
+ if(!thread)
+ return -ENOENT;
+ ret = Threads_Wake( thread );
+ //Log_Debug("Threads", "TID %i woke %i (%p)", Threads_GetTID(), TID, thread);
+ return ret;
+}
+
+void Threads_ToggleTrace(int TID)
+{
+ tThread *thread = Threads_GetThread(TID);
+ if(!thread) return ;
+ thread->bInstrTrace = !thread->bInstrTrace;
+}
+
+/**
+ * \brief Adds a thread to the active queue
+ */
+void Threads_AddActive(tThread *Thread)
+{
+ SHORTLOCK( &glThreadListLock );
+
+ if( Thread->Status == THREAD_STAT_ACTIVE ) {
+ tThread *cur = Proc_GetCurThread();
+ Log_Warning("Threads", "WTF, %p CPU%i %p (%i %s) is adding %p (%i %s) when it is active",
+ __builtin_return_address(0),
+ GetCPUNum(), cur, cur->TID, cur->ThreadName, Thread, Thread->TID, Thread->ThreadName);
+ SHORTREL( &glThreadListLock );
+ return ;
+ }
+
+ // Set state
+ Thread->Status = THREAD_STAT_ACTIVE;
+// Thread->CurCPU = -1;
+ // Add to active list
+ {
+ #if SCHEDULER_TYPE == SCHED_RR_PRI
+ tThreadList *list = &gaActiveThreads[Thread->Priority];
+ #else
+ tThreadList *list = &gActiveThreads;
+ #endif
+ Threads_int_AddToList( list, Thread );
+ }
+
+ // Update bookkeeping
+ giNumActiveThreads ++;
+
+ #if SCHEDULER_TYPE == SCHED_LOTTERY
+ {
+ int delta;
+ // Only change the ticket count if the thread is un-scheduled
+ if(Thread->CurCPU != -1)
+ delta = 0;
+ else
+ delta = caiTICKET_COUNTS[ Thread->Priority ];
+
+ giFreeTickets += delta;
+ # if DEBUG_TRACE_TICKETS
+ Log("CPU%i %p (%i %s) added, new giFreeTickets = %i [+%i]",
+ GetCPUNum(), Thread, Thread->TID, Thread->ThreadName,
+ giFreeTickets, delta
+ );
+ # endif
+ }
+ #endif
+
+ SHORTREL( &glThreadListLock );
+}
+
+/**
+ * \brief Removes the current thread from the active queue
+ * \warning This should ONLY be called with the lock held
+ * \return Current thread pointer