+ // Free name
+ if( IsHeap(Thread->ThreadName) )
+ free(Thread->ThreadName);
+
+ // Remove from global list
+ // TODO: Lock this too
+ if( Thread == gAllThreads )
+ gAllThreads = Thread->GlobalNext;
+ else
+ Thread->GlobalPrev->GlobalNext = Thread->GlobalNext;
+
+ free(Thread);
+}
+
+/**
+ * \fn void Threads_SetName(const char *NewName)
+ * \brief Sets the current thread's name
+ * \param NewName New name for the thread
+ * \return Boolean Failure
+ */
+int Threads_SetName(const char *NewName)
+{
+ tThread *cur = Proc_GetCurThread();
+ char *oldname = cur->ThreadName;
+
+ // NOTE: There is a possibility of non-thread safety here
+ // A thread could read the current name pointer before it is zeroed
+
+ cur->ThreadName = NULL;
+
+ if( IsHeap(oldname) ) free( oldname );
+
+ cur->ThreadName = strdup(NewName);
+ return 0;
+}
+
+/**
+ * \fn char *Threads_GetName(int ID)
+ * \brief Gets a thread's name
+ * \param ID Thread ID (-1 indicates current thread)
+ * \return Pointer to name
+ * \retval NULL Failure
+ */
+char *Threads_GetName(tTID ID)
+{
+ if(ID == -1) {
+ return Proc_GetCurThread()->ThreadName;
+ }
+ return Threads_GetThread(ID)->ThreadName;
+}
+
+/**
+ * \fn void Threads_SetPriority(tThread *Thread, int Pri)
+ * \brief Sets the priority of a task
+ * \param Thread Thread to update ticket count (NULL means current thread)
+ * \param Pri New priority
+ */
+void Threads_SetPriority(tThread *Thread, int Pri)
+{
+ // Get current thread
+ if(Thread == NULL) Thread = Proc_GetCurThread();
+ // Bounds checking
+ // - If < 0, set to lowest priority
+ // - Minumum priority is actualy a high number, 0 is highest
+ if(Pri < 0) Pri = MIN_PRIORITY;
+ if(Pri > MIN_PRIORITY) Pri = MIN_PRIORITY;
+
+ // Do we actually have to do anything?
+ if( Pri == Thread->Priority ) return;
+
+ #if SCHEDULER_TYPE == SCHED_RR_PRI
+ SHORTLOCK( &glThreadListLock );
+ // Remove from old priority
+ Threads_int_DelFromQueue( &gaActiveThreads[Thread->Priority], Thread );
+ // And add to new
+ Thread->Next = gaActiveThreads[Pri];
+ gaActiveThreads[Pri] = Thread;
+ Thread->Priority = Pri;
+ SHORTREL( &glThreadListLock );
+ #else
+ // If this isn't the current thread, we need to lock
+ if( Thread != Proc_GetCurThread() )