提交 7bfcdbe7 编写于 作者: S siyangy 提交者: Jiangtao Hu

Dreamview: fix a relative_map race

上级 661d041e
......@@ -963,6 +963,13 @@ template <>
void SimulationWorldService::UpdateSimulationWorld(const MapMsg &map_msg) {
if (map_msg.has_hdmap()) {
relative_map_.CopyFrom(map_msg.hdmap());
for (int i = 0; i < relative_map_.lane_size(); ++i) {
auto *lane = relative_map_.mutable_lane(i);
lane->clear_left_sample();
lane->clear_right_sample();
lane->clear_left_road_sample();
lane->clear_right_road_sample();
}
}
}
......
......@@ -81,10 +81,12 @@ void SimulationWorldUpdater::RegisterMessageHandlers() {
map_ws_->RegisterMessageHandler(
"RetrieveRelativeMapData",
[this](const Json &json, WebSocketHandler::Connection *conn) {
std::string retrieved_map_string;
sim_world_service_.GetRelativeMap().SerializeToString(
&retrieved_map_string);
map_ws_->SendBinaryData(conn, retrieved_map_string, true);
std::string to_send;
{
boost::shared_lock<boost::shared_mutex> reader_lock(mutex_);
to_send = relative_map_string_;
}
map_ws_->SendBinaryData(conn, to_send, true);
});
websocket_->RegisterMessageHandler(
......@@ -348,6 +350,8 @@ void SimulationWorldUpdater::OnTimer(const ros::TimerEvent &event) {
sim_world_service_.GetWireFormatString(
FLAGS_sim_map_radius, &simulation_world_,
&simulation_world_with_planning_data_);
sim_world_service_.GetRelativeMap().SerializeToString(
&relative_map_string_);
}
}
......
......@@ -136,6 +136,9 @@ class SimulationWorldUpdater {
std::string simulation_world_;
std::string simulation_world_with_planning_data_;
// Received relative map data in wire format.
std::string relative_map_string_;
// Mutex to protect concurrent access to simulation_world_json_.
// NOTE: Use boost until we have std version of rwlock support.
boost::shared_mutex mutex_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册