Example #1
0
void* _ThreadHandler(void *pData)
{
	CThread *pThread = (CThread*)pData;
	
	pThread->m_eState = CThread::THREADSTATE_RUNNING;
	while(1)
	{
		struct CThread::CmdNode node;
		pThread->m_cqLock.Lock();
		if(pThread->m_vCmdQueue.size())
		{
			node = pThread->m_vCmdQueue.at(0);
			pThread->m_vCmdQueue.erase(pThread->m_vCmdQueue.begin());
			pThread->m_cqLock.Unlock();
			
			switch(node.cmd)
			{
			case CThread::CMD_RUN:
				pThread->m_eState = CThread::THREADSTATE_RUNNING;
				break;
			case CThread::CMD_PAUSE:
				pThread->m_eState = CThread::THREADSTATE_PAUSED;
				break;
			case CThread::CMD_CONTINUE:
				pThread->m_eState = CThread::THREADSTATE_RUNNING;
				break;
			}
		}
		else
		{
			pThread->m_cqLock.Unlock();
			node.cmd = CThread::CMD_NONE;
			node.hEvent = NULL;
		}
		pThread->CommandHandler(node.cmd);
		if(node.hEvent) PA_EventSet(node.hEvent);
		if(node.cmd == CThread::CMD_STOP)
			break;
	}
	pThread->m_eState = CThread::THREADSTATE_STOPPED;
	return NULL;
}