Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
36cae1fe
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
36cae1fe
编写于
9月 11, 2018
作者:
fengqikai1414
提交者:
Liangliang Zhang
9月 11, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cybertron: update custom task api
上级
e601aa23
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
14 deletion
+58
-14
framework/CMakeLists.txt
framework/CMakeLists.txt
+6
-0
framework/cybertron/cybertron.h
framework/cybertron/cybertron.h
+40
-7
framework/examples/user_defined_task.cpp
framework/examples/user_defined_task.cpp
+12
-7
未找到文件。
framework/CMakeLists.txt
浏览文件 @
36cae1fe
...
...
@@ -97,5 +97,11 @@ install(DIRECTORY "cybertron"
PATTERN
"*.h"
)
install
(
DIRECTORY
"
${
CMAKE_CURRENT_BINARY_DIR
}
/cybertron"
DESTINATION
"include"
FILES_MATCHING
PATTERN
"*.pb.h"
)
enable_testing
()
#add_subdirectory(cybertron/test)
framework/cybertron/cybertron.h
浏览文件 @
36cae1fe
...
...
@@ -27,19 +27,52 @@
#include "cybertron/time/time.h"
#include "cybertron/timer/timer.h"
#define LOG_DEBUG ADEBUG
#define LOG_INFO AINFO
#define LOG_WARN AWARN
#define LOG_ERROR AERROR
#define XLOG_ERROR(...) printf(__VA_ARGS__);
namespace
apollo
{
namespace
cybertron
{
std
::
unique_ptr
<
Node
>
CreateNode
(
const
std
::
string
&
node_name
,
const
std
::
string
&
name_space
=
""
);
template
<
typename
Function
>
std
::
unique_ptr
<
Task
<>>
CreateTask
(
const
std
::
string
&
name
,
Function
&&
f
,
const
uint8_t
num_threads
=
1
)
{
if
(
!
OK
())
{
return
nullptr
;
}
std
::
unique_ptr
<
Task
<>>
task
(
new
Task
<>
(
name
,
std
::
forward
<
Function
>
(
f
),
num_threads
));
return
std
::
move
(
task
);
}
template
<
typename
T
,
typename
Function
>
std
::
unique_ptr
<
Task
<
T
>>
CreateTask
(
const
std
::
string
&
name
,
Function
&&
f
,
const
uint8_t
&
num_threads
=
1
)
{
if
(
!
OK
())
{
return
nullptr
;
}
std
::
unique_ptr
<
Task
<
T
>>
task
(
new
Task
<
T
>
(
name
,
std
::
forward
<
Function
>
(
f
),
num_threads
));
return
std
::
move
(
task
);
}
inline
static
void
Yield
()
{
if
(
croutine
::
CRoutine
::
GetCurrentRoutine
())
{
croutine
::
CRoutine
::
Yield
();
}
else
{
std
::
this_thread
::
yield
();
}
}
inline
static
void
USleep
(
useconds_t
usec
)
{
auto
routine
=
croutine
::
CRoutine
::
GetCurrentRoutine
();
if
(
routine
==
nullptr
)
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
microseconds
{
usec
});
}
else
{
routine
->
Sleep
(
usec
);
}
}
}
// namespace cybertron
}
// namespace apollo
#endif // CYBERTRON_CYBERTRON_H_
framework/examples/user_defined_task.cpp
浏览文件 @
36cae1fe
...
...
@@ -22,8 +22,8 @@
static
const
uint8_t
num_threads
=
3
;
using
apollo
::
cybertron
::
proto
::
Driver
;
using
apollo
::
cybertron
::
Task
;
using
apollo
::
cybertron
::
proto
::
Driver
;
struct
Message
{
uint64_t
msg_id
;
...
...
@@ -34,21 +34,24 @@ struct Message {
void
AsyncDataProcessor
()
{
for
(;;)
{
AERROR
<<
"AsyncDataProcesor is running."
;
us
leep
(
5000000
);
apollo
::
cybertron
::
US
leep
(
5000000
);
}
}
void
TaskProcessor
(
const
std
::
shared_ptr
<
Message
>&
msg
)
{
AERROR
<<
"Task Processor["
<<
msg
->
task_id
<<
"] is running: "
<<
msg
->
msg_id
;
us
leep
(
100000
);
apollo
::
cybertron
::
US
leep
(
100000
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
// Init
apollo
::
cybertron
::
Init
(
argv
[
0
]);
Task
<>
task0
(
"async_data_processor"
,
&
AsyncDataProcessor
);
Task
<
Message
>
task1
(
"task_processor"
,
&
TaskProcessor
,
num_threads
);
// Task<> task0("async_data_processor", &AsyncDataProcessor);
auto
task0
=
apollo
::
cybertron
::
CreateTask
(
"async_data_processor"
,
&
AsyncDataProcessor
);
auto
task1
=
apollo
::
cybertron
::
CreateTask
<
Message
>
(
"task_processor"
,
&
TaskProcessor
,
num_threads
);
// Run
uint64_t
i
=
0
;
...
...
@@ -57,9 +60,11 @@ int main(int argc, char* argv[]) {
auto
msg
=
std
::
make_shared
<
Message
>
();
msg
->
msg_id
=
i
++
;
msg
->
task_id
=
j
;
task1
.
Execute
(
msg
);
task1
->
Execute
(
msg
);
apollo
::
cybertron
::
Yield
();
apollo
::
cybertron
::
USleep
(
10000
);
}
task1
.
Wait
();
task1
->
Wait
();
}
AERROR
<<
"All task are finished."
;
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录