Exemple #1
0
void CThreadInfo::Init()
{
//	FILETIME stNow;
//	GetLocalTime(&stNow);

	SetIsValid    ( false );
	SetThreadID    ( 0 );
//	SetCreationTime( stNow );
//	SetExitTime    ( stNow );
//	SetKernelTime  ( stNow );
//	SetUserTime	   ( stNow );

	SetKernelDiff ( 0 );
	SetUserDiff   ( 0 );
}
BOOL CWin32Thread::SetPriority(CGenericThread::ThreadPriority aPriority)
{
	try
	{
		static const int iThreadPriority[]={THREAD_PRIORITY_IDLE,
											THREAD_PRIORITY_LOWEST,
											THREAD_PRIORITY_BELOW_NORMAL,
											THREAD_PRIORITY_NORMAL,
											THREAD_PRIORITY_ABOVE_NORMAL,
											THREAD_PRIORITY_HIGHEST,
											THREAD_PRIORITY_TIME_CRITICAL};

		//Do we have a thread
		if (GetThreadStatus()==tsStopped)
		{
			//Recreate the thread
			//Our thread ID
			DWORD dwThreadID;

			//Create the thread in suspend mode
			m_hThread=CreateThread(NULL,
   								   0,
								   Win32Thread,
								   this,
								   CREATE_SUSPENDED,
								   &dwThreadID);

			//Check if created
			if (m_hThread)
			{
				//Set the thread ID
				SetThreadID(dwThreadID);

				//Set the status
				SetThreadStatus(tsSuspended);
			}
			else
				//Can't run
				return FALSE;
		}

		//Now we can set the priority
		return SetThreadPriority(m_hThread,
								 iThreadPriority[aPriority]);
	}
	ERROR_HANDLER_RETURN("SetPriority",FALSE)
}
BOOL CWin32Thread::Start(LPVOID pData)
{
	try
	{
		if (GetThreadStatus()==tsStopped)
		{
			//Recreate the thread
			//Our thread ID
			DWORD dwThreadID;

			//Create the thread in suspend mode
			m_hThread=CreateThread(NULL,
   								   0,
								   Win32Thread,
								   this,
								   CREATE_SUSPENDED,
								   &dwThreadID);

			//Check if created
			if (m_hThread)
			{
				//Set the thread ID
				SetThreadID(dwThreadID);

				//Set the status
				SetThreadStatus(tsSuspended);
			}
			else
				//Can't run
				return FALSE;
		}
		else if (GetThreadStatus()!=tsSuspended)
			return FALSE;

		//Start the thread
		CGenericThread::Start(pData);

		//Resume the thread
		if (m_hThread)
			if (ResumeThread(m_hThread)!=-1)
				//We are running
				return TRUE;

		return FALSE;
	}
	ERROR_HANDLER_RETURN("Start",FALSE)
}
Exemple #4
0
CThreadInfo& CThreadInfo::operator=( CThreadInfo& src )
{
	if ( this == &src )
		return *this;

	SetIsValid     ( src.IsValid()			);
	SetThreadID    ( src.GetThreadID()		);
	SetCreationTime( src.GetCreationTime()	);
	SetExitTime    ( src.GetExitTime()		);
	SetKernelTime  ( src.GetKernelTime()	);
	SetUserTime	   ( src.GetUserTime()		);

	SetKernelDiff  ( src.GetKernelDiff()	);
	SetUserDiff    ( src.GetUserDiff()		);

	return *this;
}
KOMODIA_NAMESPACE_START

#define CWin32Thread_Class "CWin32Thread"

CWin32Thread::CWin32Thread(LPGenericThreadProc pThreadProc) : CGenericThread(pThreadProc),
															  m_hThread(0)
{
	try
	{
		//Set our name
		SetName(CWin32Thread_Class);

		//Create the thread
		if (GetThreadProc())
		{
			//Our thread ID
			DWORD dwThreadID;

			//Create the thread in suspend mode
			m_hThread=CreateThread(NULL,
   								   0,
								   Win32Thread,
								   this,
								   CREATE_SUSPENDED,
								   &dwThreadID);

			//Check if created
			if (m_hThread)
			{
				//Set the thread ID
				SetThreadID(dwThreadID);

				//Set the status
				SetThreadStatus(tsSuspended);
			}
			else
				//An error
				throw std::string("Failed to create thread!");
		}
		else
			//Throw the error
			throw std::string("No thread proc!");
	}
	ERROR_HANDLER_RETHROW("CWin32Thread")
}