EventThread.cpp 820 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "stdafx.h"
  2. #include "EventThread.h"
  3. #include "EventPool.h"
  4. #include "ThreadPool.h"
  5. CEventThread::CEventThread()
  6. {
  7. }
  8. CEventThread::~CEventThread()
  9. {
  10. }
  11. THREADSTATUS CEventThread::Run()
  12. {
  13. if(CEventPool::GetInstance()->GetEventNum() > 0)
  14. WakeUp();
  15. m_ThreadStatus = THREADSTATUS_WAIT;
  16. WaitForSingleObject(m_hSemaphore, INFINITE);
  17. if(WaitForSingleObject(m_hExit, 0) == WAIT_OBJECT_0)
  18. {
  19. m_ThreadStatus = THREADSTATUS_EXIT;
  20. return m_ThreadStatus;
  21. }
  22. m_ThreadStatus = THREADSTATUS_RUNNING;
  23. // 是否存在任务
  24. LPSEVENT lpEvent = CEventPool::GetInstance()->TakeOutEvent();
  25. if(lpEvent == NULL)
  26. return m_ThreadStatus;
  27. // 添加到
  28. int nRet = CThreadPool::GetInstance()->AddEventItem(lpEvent);
  29. if(nRet != 1)
  30. {
  31. // 删除事件
  32. CEventPool::GetInstance()->AddEvent(lpEvent);
  33. }
  34. return m_ThreadStatus;
  35. }