All pastes #355023 Raw Edit

Thread Class

public cpp v1 · immutable
·published 2007-02-14 07:55 UTC
rendered paste body
#include <windows.h>#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, ...){	va_list pVaList;	char *szBuffer = {0};	va_start(pVaList, strName);	_vsnprintf(szBuffer, sizeof(szBuffer) - 1, strName.c_str(), pVaList);	va_end(pVaList);#ifdef _DEBUG	DebugConsole("DEBUG -> Creating a thread.");#endif	DWORD dwId;	Threads[Threads.size()].strName = szBuffer;	Threads[Threads.size()].iPriority = Priority;	Threads[Threads.size()].Thread = CreateThread(NULL, 0, lpThread, lpParam, 0, &dwId);	Threads[Threads.size()].ThreadId = Threads.size();#ifdef _DEBUG	DebugConsole("Adding created thread to list.");#endif	if (Threads[Threads.size()].Thread != INVALID_HANDLE_VALUE)	{		cThreadList::Priority(Threads[Threads.size()].ThreadId, Threads[Threads.size()].iPriority);	}#ifdef _DEBUG	DebugConsole("DEBUG -> Added Thread %s(%d) with a priority of %d Successfully.",		Threads[Threads.size()].strName,Threads[Threads.size()].ThreadId,Threads[Threads.size()].iPriority);#endif	return Threads[Threads.size()].ThreadId;}int cThreadList::Find(string strName){	for(int i=0;i<Threads.size();i++)	{		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);	}	return;}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);	}	return;}vector<string> cThreadList::List(){	vector<string> threads;	for(int i = 0;i<Threads.size();i++)	{		threads[i] = Threads[i].strName;	}	return threads;}