libcopp
2.3.1
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
y
Functions
_
a
c
d
f
g
h
i
m
o
p
r
s
t
w
y
Variables
_
a
b
c
d
e
f
g
h
l
m
o
p
r
s
t
u
w
x
Typedefs
Enumerations
Enumerator
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
y
~
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
y
~
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Typedefs
_
a
b
c
d
e
f
h
i
j
l
m
n
o
p
r
s
t
u
v
w
Enumerations
Enumerator
e
l
s
u
Related Symbols
_
d
e
i
l
o
r
s
w
Files
File List
Globals
All
_
b
c
e
g
j
l
m
o
p
r
s
t
u
w
Functions
b
c
g
j
m
o
p
r
s
t
Variables
b
c
g
m
s
t
Typedefs
Enumerations
Enumerator
c
e
Macros
_
c
l
m
s
t
u
w
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
sample
sample_readme_1.cpp
Go to the documentation of this file.
1
#include <inttypes.h>
2
#include <stdint.h>
3
#include <cstdio>
4
#include <cstring>
5
#include <iostream>
6
7
// include context header file
8
#include <
libcopp/coroutine/coroutine_context_container.h
>
9
10
// define a coroutine runner
11
int
my_runner
(
void
*) {
12
copp::coroutine_context *addr = copp::this_coroutine::get_coroutine();
13
14
std::cout <<
"cortoutine "
<< addr <<
" is running."
<< std::endl;
15
16
addr->yield();
17
18
std::cout <<
"cortoutine "
<< addr <<
" is resumed."
<< std::endl;
19
20
return
1;
21
}
11
int
my_runner
(
void
*) {
…
}
22
23
int
main
() {
24
typedef
copp::coroutine_context_default coroutine_type;
25
26
// create a coroutine
27
copp::coroutine_context_default::ptr_t
co_obj = coroutine_type::create(
my_runner
);
28
std::cout <<
"cortoutine "
<< co_obj <<
" is created."
<< std::endl;
29
30
// start a coroutine
31
co_obj->start();
32
33
// yield from my_runner
34
std::cout <<
"cortoutine "
<< co_obj <<
" is yield."
<< std::endl;
35
co_obj->resume();
36
37
std::cout <<
"cortoutine "
<< co_obj <<
" exit and return "
<< co_obj->get_ret_code() <<
"."
<< std::endl;
38
return
0;
39
}
23
int
main
() {
…
}
coroutine_context_container::ptr_t
ptr_type ptr_t
Definition
coroutine_context_container.h:36
my_runner
Definition
sample_default_coroutine_context.cpp:20
coroutine_context_container.h
main
int main()
Definition
sample_readme_1.cpp:23
Generated by
1.9.8