Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bdb4889 authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Execute AddHciConnection from the async manager context

AddHciConnection is called from the FdWatcher thread,
this causes a data race for accessing the TestModel state
when actions scheduled on the event thread get executed at
the same time.

Test: m root-canal && ./root-canal
Bug: 278891939
Change-Id: I8d59dca134a2a10e85073d1b7d6ed8c2e41e783c
parent 4fcb55e1
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -61,14 +61,16 @@ void TestEnvironment::initialize(std::promise<void> barrier) {
      });

  SetUpTestChannel();
  SetUpHciServer([this](std::shared_ptr<AsyncDataChannel> socket,
  SetUpHciServer([this, user_id](std::shared_ptr<AsyncDataChannel> socket,
                        AsyncDataChannelServer* srv) {
    auto transport = HciSocketTransport::Create(socket);
    if (enable_hci_sniffer_) {
      transport = HciSniffer::Create(transport);
    }
    auto device = HciDevice::Create(transport, controller_properties_file_);
    async_manager_.ExecAsync(user_id, std::chrono::milliseconds(0), [=]() {
      test_model_.AddHciConnection(device);
    });
    if (enable_hci_sniffer_) {
      auto filename = device->GetAddress().ToString() + ".pcap";
      for (auto i = 0; std::filesystem::exists(filename); i++) {
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class PhyDevice {
  using Identifier = uint32_t;

  PhyDevice(Identifier id, std::string type, std::shared_ptr<Device> device);
  PhyDevice(PhyDevice &&) = delete;
  ~PhyDevice() = default;

  void Register(PhyLayer* phy);