-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_uc_coroutine.cpp
More file actions
110 lines (87 loc) · 2.57 KB
/
test_uc_coroutine.cpp
File metadata and controls
110 lines (87 loc) · 2.57 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* =====================================================================================
*
* Filename: test_uc_coroutine.cpp
*
* Description:
*
* Version: 1.0
* Created: 2017年01月11日 11时37分00秒
* Revision: none
* Compiler: gcc
*
* Author: anonymalias (anonym_alias@163.com),
* Organization:
*
* =====================================================================================
*/
#include "uc_coroutine_pool.h"
#include <stdio.h>
UCCoroutine * coro = NULL;
int working(int arg)
{
printf("%s:%d\n", __FUNCTION__, arg);
printf("%s:before yield|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
coro->Yield_S();
printf("%s:after yield|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
}
void test_1()
{
printf("%s:start\n", __FUNCTION__);
UCCoroutinePool coro_pool;
for(int i = 1; i <= 10; ++i)
{
coro = coro_pool.Post(std::bind(working, i));
coro->Resume_P();
printf("\n%s:before resume|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
coro->Resume_P();
printf("%s:after resume|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
}
printf("%s:end\n", __FUNCTION__);
}
void test_2()
{
printf("%s:start\n", __FUNCTION__);
UCCoroutinePool coro_pool;
std::list<UCCoroutine *> running_coro_list;
for(int i = 1; i <= 10; ++i)
{
coro = coro_pool.Post(std::bind(working, i));
coro->Resume_P();
running_coro_list.push_back(coro);
}
for(int i = 1; i <= 10; ++i)
{
coro = running_coro_list.front();
running_coro_list.pop_front();
printf("\n%s:before resume|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
coro->Resume_P();
printf("%s:after resume|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
}
printf("%s:end\n", __FUNCTION__);
}
void test_3()
{
printf("%s:start\n", __FUNCTION__);
UCCoroutinePool coro_pool(1024, 512, 1024000, true);
std::list<UCCoroutine *> running_coro_list;
for(int i = 1; i <= 10; ++i)
{
coro = coro_pool.Post(std::bind(working, i));
coro->Resume_S();
running_coro_list.push_back(coro);
}
for(int i = 1; i <= 10; ++i)
{
coro = running_coro_list.front();
running_coro_list.pop_front();
printf("\n%s:before resume|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
coro->Resume_S();
printf("%s:after resume|task_id:%u\n", __FUNCTION__, coro->GetTaskID());
}
printf("%s:end\n", __FUNCTION__);
}
int main()
{
test_3();
}