Skip to content

Commit

Permalink
Merge pull request #785 from mavlink/133-race-in-grpc
Browse files Browse the repository at this point in the history
fix race condition in grpc streams
  • Loading branch information
julianoes authored Jul 8, 2019
2 parents 4ea885a + 3e75734 commit 1002ea9
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 75 deletions.
10 changes: 8 additions & 2 deletions src/backend/src/core/core_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ class CoreServiceImpl final : public mavsdk::rpc::core::CoreService::Service {
const rpc::core::SubscribeConnectionStateRequest * /* request */,
grpc::ServerWriter<rpc::core::ConnectionStateResponse> *writer) override
{
_dc.register_on_discover([&writer](const uint64_t uuid) {
std::mutex connection_state_mutex{};

_dc.register_on_discover([&writer, &connection_state_mutex](const uint64_t uuid) {
const auto rpc_connection_state_response = createRpcConnectionStateResponse(uuid, true);

std::lock_guard<std::mutex> lock(connection_state_mutex);
writer->Write(rpc_connection_state_response);
});

_dc.register_on_timeout([&writer](const uint64_t uuid) {
_dc.register_on_timeout([&writer, &connection_state_mutex](const uint64_t uuid) {
const auto rpc_connection_state_response =
createRpcConnectionStateResponse(uuid, false);

std::lock_guard<std::mutex> lock(connection_state_mutex);
writer->Write(rpc_connection_state_response);
});

Expand Down
Loading

0 comments on commit 1002ea9

Please sign in to comment.