12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include "stdafx.h"
- #include "EventThread.h"
- #include "EventPool.h"
- #include "ThreadPool.h"
- CEventThread::CEventThread()
- {
-
- }
- CEventThread::~CEventThread()
- {
-
- }
- THREADSTATUS CEventThread::Run()
- {
- if(CEventPool::GetInstance()->GetEventNum() > 0)
- WakeUp();
- m_ThreadStatus = THREADSTATUS_WAIT;
- WaitForSingleObject(m_hSemaphore, INFINITE);
- if(WaitForSingleObject(m_hExit, 0) == WAIT_OBJECT_0)
- {
- m_ThreadStatus = THREADSTATUS_EXIT;
- return m_ThreadStatus;
- }
- m_ThreadStatus = THREADSTATUS_RUNNING;
- // 是否存在任务
- LPSEVENT lpEvent = CEventPool::GetInstance()->TakeOutEvent();
- if(lpEvent == NULL)
- return m_ThreadStatus;
- // 添加到
- int nRet = CThreadPool::GetInstance()->AddEventItem(lpEvent);
- if(nRet != 1)
- {
- // 删除事件
- CEventPool::GetInstance()->AddEvent(lpEvent);
- }
- return m_ThreadStatus;
- }
|