• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _WELS_THREAD_POOL_TEST_H_
2 #define _WELS_THREAD_POOL_TEST_H_
3 
4 #include "WelsLock.h"
5 #include "WelsThreadPool.h"
6 
7 using namespace WelsCommon;
8 
9 class CThreadPoolTest : public IWelsTaskSink {
10  public:
CThreadPoolTest()11   CThreadPoolTest() {
12     m_iTaskCount = 0;
13   }
14 
~CThreadPoolTest()15   ~CThreadPoolTest() {}
16 
OnTaskExecuted(IWelsTask * pTask)17   virtual int32_t OnTaskExecuted (IWelsTask* pTask) {
18     WelsCommon::CWelsAutoLock cAutoLock (m_cTaskCountLock);
19     m_iTaskCount ++;
20     //fprintf(stdout, "Task execute over count is %d\n", m_iTaskCount);
21     return cmResultSuccess;
22   }
23 
OnTaskCancelled(IWelsTask * pTask)24   virtual int32_t OnTaskCancelled (IWelsTask* pTask) {
25     WelsCommon::CWelsAutoLock cAutoLock (m_cTaskCountLock);
26     m_iTaskCount ++;
27     //fprintf(stdout, "Task execute cancelled count is %d\n", m_iTaskCount);
28     return cmResultSuccess;
29   }
30 
OnTaskExecuted()31   virtual int32_t OnTaskExecuted() {
32     WelsCommon::CWelsAutoLock cAutoLock (m_cTaskCountLock);
33     m_iTaskCount ++;
34     //fprintf(stdout, "Task execute over count is %d\n", m_iTaskCount);
35     return cmResultSuccess;
36   }
37 
OnTaskCancelled()38   virtual int32_t OnTaskCancelled() {
39     WelsCommon::CWelsAutoLock cAutoLock (m_cTaskCountLock);
40     m_iTaskCount ++;
41     //fprintf(stdout, "Task execute cancelled count is %d\n", m_iTaskCount);
42     return cmResultSuccess;
43   }
44 
GetTaskCount()45   int32_t  GetTaskCount() {
46     return m_iTaskCount;
47   }
48 
49  private:
50   int32_t  m_iTaskCount;
51   WelsCommon::CWelsLock  m_cTaskCountLock;
52 };
53 
54 
55 
56 class CSimpleTask : public IWelsTask {
57  public:
58   static uint32_t id;
59 
CSimpleTask(WelsCommon::IWelsTaskSink * pSink)60   CSimpleTask (WelsCommon::IWelsTaskSink* pSink) : IWelsTask (pSink) {
61     m_uiID = id ++;
62   }
63 
~CSimpleTask()64   virtual ~CSimpleTask() {
65   }
66 
Execute()67   virtual int32_t Execute() {
68     uint32_t uiSleepTime = (m_uiID > 99) ? 10 : m_uiID;
69     WelsSleep (uiSleepTime);
70     //printf ("Task %d executing\n", m_uiID);
71     return cmResultSuccess;
72   }
73 
74  private:
75   uint32_t m_uiID;
76 };
77 
78 #endif
79 
80