Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
e7c95182
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,发现更多精彩内容 >>
提交
e7c95182
编写于
12月 04, 2018
作者:
R
Ronggui Peng
提交者:
Jiangtao Hu
12月 13, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Drivers: add canbus & camera async future wait when exit
上级
e1f29dce
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
6 deletion
+23
-6
modules/drivers/camera/camera_component.cc
modules/drivers/camera/camera_component.cc
+9
-1
modules/drivers/camera/camera_component.h
modules/drivers/camera/camera_component.h
+5
-0
modules/drivers/canbus/can_comm/can_receiver.h
modules/drivers/canbus/can_comm/can_receiver.h
+9
-5
未找到文件。
modules/drivers/camera/camera_component.cc
浏览文件 @
e7c95182
...
...
@@ -77,11 +77,12 @@ bool CameraComponent::Init() {
}
writer_
=
node_
->
CreateWriter
<
Image
>
(
camera_config_
->
channel_name
());
cyber
::
Async
(
&
CameraComponent
::
run
,
this
);
async_result_
=
cyber
::
Async
(
&
CameraComponent
::
run
,
this
);
return
true
;
}
void
CameraComponent
::
run
()
{
running_
.
exchange
(
true
);
while
(
!
cyber
::
IsShutdown
())
{
if
(
!
camera_device_
->
wait_for_device
())
{
// sleep for next check
...
...
@@ -109,6 +110,13 @@ void CameraComponent::run() {
}
}
CameraComponent
::~
CameraComponent
()
{
if
(
running_
.
load
())
{
running_
.
exchange
(
false
);
async_result_
.
wait
();
}
}
}
// namespace camera
}
// namespace drivers
}
// namespace apollo
modules/drivers/camera/camera_component.h
浏览文件 @
e7c95182
...
...
@@ -18,6 +18,8 @@
#include <memory>
#include <vector>
#include <future>
#include <atomic>
#include "cyber/cyber.h"
#include "modules/drivers/proto/sensor_image.pb.h"
...
...
@@ -38,6 +40,7 @@ using apollo::drivers::camera::config::Config;
class
CameraComponent
:
public
Component
<>
{
public:
bool
Init
()
override
;
~
CameraComponent
();
private:
void
run
();
...
...
@@ -52,6 +55,8 @@ class CameraComponent : public Component<> {
int
index_
=
0
;
int
buffer_size_
=
16
;
const
int32_t
MAX_IMAGE_SIZE
=
20
*
1024
*
1024
;
std
::
future
<
void
>
async_result_
;
std
::
atomic
<
bool
>
running_
=
{
false
};
};
CYBER_REGISTER_COMPONENT
(
CameraComponent
)
...
...
modules/drivers/canbus/can_comm/can_receiver.h
浏览文件 @
e7c95182
...
...
@@ -27,6 +27,8 @@
#include <sstream>
#include <thread>
#include <vector>
#include <future>
#include <atomic>
#include "cyber/common/macros.h"
#include "cyber/cyber.h"
...
...
@@ -98,12 +100,13 @@ class CanReceiver {
int32_t
Start
(
bool
is_blocked
);
private:
bool
is_running_
=
false
;
std
::
atomic
<
bool
>
is_running_
=
{
false
}
;
// CanClient, MessageManager pointer life is managed by outer program
CanClient
*
can_client_
=
nullptr
;
MessageManager
<
SensorType
>
*
pt_manager_
=
nullptr
;
bool
enable_log_
=
false
;
bool
is_init_
=
false
;
std
::
future
<
void
>
async_result_
;
DISALLOW_COPY_AND_ASSIGN
(
CanReceiver
);
};
...
...
@@ -182,7 +185,7 @@ void CanReceiver<SensorType>::RecvThreadFunc() {
template
<
typename
SensorType
>
bool
CanReceiver
<
SensorType
>::
IsRunning
()
const
{
return
is_running_
;
return
is_running_
.
load
()
;
}
template
<
typename
SensorType
>
...
...
@@ -190,9 +193,9 @@ template <typename SensorType>
if
(
is_init_
==
false
)
{
return
::
apollo
::
common
::
ErrorCode
::
CANBUS_ERROR
;
}
is_running_
=
true
;
is_running_
.
exchange
(
true
)
;
cyber
::
Async
(
&
CanReceiver
<
SensorType
>::
RecvThreadFunc
,
this
);
async_result_
=
cyber
::
Async
(
&
CanReceiver
<
SensorType
>::
RecvThreadFunc
,
this
);
return
::
apollo
::
common
::
ErrorCode
::
OK
;
}
...
...
@@ -200,7 +203,8 @@ template <typename SensorType>
void
CanReceiver
<
SensorType
>::
Stop
()
{
if
(
IsRunning
())
{
AINFO
<<
"Stopping can client receiver ..."
;
is_running_
=
false
;
is_running_
.
exchange
(
false
);
async_result_
.
wait
();
}
else
{
AINFO
<<
"Can client receiver is not running."
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录