-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestTaskPool.cpp
More file actions
50 lines (43 loc) · 988 Bytes
/
TestTaskPool.cpp
File metadata and controls
50 lines (43 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "../src/TaskPool.h"
#include "../src/TQFactory.h"
#include "../src/BaseTask.h"
#include <cstdio>
#include <chrono>
#include <thread>
using namespace tq;
class PrintTask : public BaseTask
{
public:
PrintTask(int counter):_count(counter){
}
void Main()
{
printf("task number:%ld\n",_count);
}
TaskCategory GetCategory() const
{
return 1;
}
private:
int _count;
};
void TaskRecycle(ITask* task,void* context)
{
((TaskPool<PrintTask> *)context)->RecycleTask((PrintTask*)task);
}
int main(int argc, const char* argv[])
{
printf("main\n");
TaskPool<PrintTask> pool;
IQueue* q = TQFactory::CreateDefaultQueue();
q->SetTaskRecycler(1,TaskRecycle,&pool);
q->Start(1);
for(int i =0;i<10000;++i)
{
q->AddTask(pool.GetTask(PrintTask(i)));
std::this_thread::sleep_for(std::chrono::microseconds(10));
}
q->WaitForFinish();
TQFactory::ReleaseQueue(q);
return 0;
}