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_default_coroutine_context.cpp
Go to the documentation of this file.
1
/*
2
* sample_default_manager.cpp
3
*
4
* Created on: 2014年3月17日
5
* Author: owent
6
*
7
* Released under the MIT license
8
*/
9
10
#include <inttypes.h>
11
#include <stdint.h>
12
#include <cstdio>
13
#include <cstring>
14
#include <iostream>
15
16
// include manager header file
17
#include <
libcopp/coroutine/coroutine_context_container.h
>
18
19
// define a coroutine runner
20
class
my_runner
{
21
public
:
22
int
operator()
(
void
*) {
23
// ... your code here ...printf("cortoutine %" PRIxPTR " exit and return %d.\n", (intptr_t)&co_obj,
24
// co_obj.get_ret_code());
25
copp::coroutine_context_default *addr = copp::this_coroutine::get<copp::coroutine_context_default>();
26
std::cout <<
"cortoutine "
<< addr <<
" is running."
<< std::endl;
27
28
addr->yield();
29
std::cout <<
"cortoutine "
<< addr <<
" is resumed."
<< std::endl;
30
31
return
1;
32
}
22
int
operator()
(
void
*) {
…
}
33
};
20
class
my_runner
{
…
};
34
35
int
main
() {
36
// create a coroutine
37
copp::coroutine_context_default::ptr_t
co_obj =
copp::coroutine_context_default::create
(
my_runner
());
38
std::cout <<
"cortoutine "
<< co_obj.get() <<
" is created."
<< std::endl;
39
40
// start a coroutine
41
co_obj->start();
42
43
// yield from runner
44
std::cout <<
"cortoutine "
<< co_obj.get() <<
" is yield."
<< std::endl;
45
co_obj->resume();
46
47
std::cout <<
"cortoutine "
<< co_obj.get() <<
" exit and return "
<< co_obj->get_ret_code() <<
"."
<< std::endl;
48
return
0;
49
}
35
int
main
() {
…
}
coroutine_context_container::create
static ptr_type create(callback_type &&runner, allocator_type &alloc, size_t stack_sz=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
create and init coroutine with specify runner and specify stack size
Definition
coroutine_context_container.h:71
coroutine_context_container::ptr_t
ptr_type ptr_t
Definition
coroutine_context_container.h:36
my_runner
Definition
sample_default_coroutine_context.cpp:20
my_runner::operator()
int operator()(void *)
Definition
sample_default_coroutine_context.cpp:22
coroutine_context_container.h
main
int main()
Definition
sample_default_coroutine_context.cpp:35
Generated by
1.9.8