#include #include "Threads.h" #include "IrcBase.h" #include "Debug.h" #include "cXorString.h" cThreadList tList; cThreadList::cThreadList(){} int cThreadList::Add(int Priority, LPTHREAD_START_ROUTINE lpThread, LPVOID lpParam, string strName) { string::size_type tSize; #ifdef _DEBUG DebugConsole("DEBUG -> Creating a thread."); #endif Thread_s thread; Threads.push_back(thread); tSize = Threads.size()-1; Threads[tSize].strName = strName; Threads[tSize].iPriority = Priority; Threads[tSize].Thread = CreateThread(NULL, 0, lpThread, lpParam, 0, 0); Threads[tSize].ThreadId = tSize; if (Threads[tSize].Thread != INVALID_HANDLE_VALUE) { cThreadList::Priority(Threads[tSize].ThreadId, Threads[tSize].iPriority); } #ifdef _DEBUG DebugConsole("DEBUG -> Added Thread %s(%d) with a priority of %d Successfully.", Threads[tSize].strName.c_str(),Threads[tSize].ThreadId,Threads[tSize].iPriority); #endif return Threads[tSize].ThreadId; } int cThreadList::Find(string strName) { for(int i=0;i Comparing %s to %s.",Threads[i].strName.c_str(),strName.c_str()); #endif if(Threads[i].strName.compare(strName) == 0) return Threads[i].ThreadId; } return -1; } string cThreadList::Find(int Id) { if(Threads[Id].Thread) return Threads[Id].strName; return NULL; } bool cThreadList::Priority(int Id, int iPriority) { if(!Find(Id).empty()) { SetThreadPriority(Threads[Id].Thread,iPriority); return true; } return false; } bool cThreadList::Priority(string strName, int iPriority) { int tId = Find(strName); if( tId >= 0) { SetThreadPriority(Threads[tId].Thread,iPriority); return true; } return false; } void cThreadList::Kill(int Id) { if(!Find(Id).empty()) { Threads[Id].iPriority = 0; Threads[Id].ThreadId = 0; Threads[Id].strName.erase(); CloseHandle(Threads[Id].Thread); Threads.erase(Threads.begin() + Id); } } void cThreadList::Kill(string strName) { int tId = Find(strName); if(tId >= 0) { Threads[tId].iPriority = 0; Threads[tId].ThreadId = 0; Threads[tId].strName.erase(); CloseHandle(Threads[tId].Thread); Threads.erase(Threads.begin() + tId); } } void cThreadList::CleanUp() { Threads.erase(Threads.begin(),Threads.end()); } vector cThreadList::List() { vector threads; for(int i = 0;i