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

Commit 79c77f3f authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Remove dependency gd::handler on eventfd with wrapped API" am: 195d17bf

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1963539

Change-Id: I2039b0d30b32ae6417965fcf3743c2b72e1e6ab5
parents 35f7ccbe 195d17bf
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -183,6 +183,7 @@ cc_defaults {
        ":BluetoothL2capSources",
        ":BluetoothMetricsSources",
        ":BluetoothNeighborSources",
        ":BluetoothOsSources",
        ":BluetoothPacketSources",
        ":BluetoothShimSources",
        ":BluetoothSecuritySources",
@@ -354,6 +355,7 @@ cc_test {
        ":BluetoothHciUnitTestSources",
        ":BluetoothL2capUnitTestSources",
        ":BluetoothMetricsTestSources",
        ":BluetoothOsTestSources",
        ":BluetoothPacketTestSources",
        ":BluetoothShimTestSources",
        ":BluetoothSecurityUnitTestSources",
+14 −2
Original line number Diff line number Diff line
@@ -7,6 +7,13 @@ package {
    default_applicable_licenses: ["system_bt_license"],
}

filegroup {
    name: "BluetoothOsSources",
    srcs: [
        "handler.cc",
    ],
}

filegroup {
    name: "BluetoothOsSources_android",
    srcs: [
@@ -35,6 +42,13 @@ filegroup {
    ],
}

filegroup {
    name: "BluetoothOsTestSources",
    srcs: [
        "handler_unittest.cc",
    ],
}

filegroup {
    name: "BluetoothOsTestSources_host",
    srcs: [
@@ -48,7 +62,6 @@ filegroup {
    srcs: [
        "linux_generic/alarm.cc",
        "linux_generic/files.cc",
        "linux_generic/handler.cc",
        "linux_generic/reactor.cc",
        "linux_generic/repeating_alarm.cc",
        "linux_generic/reactive_semaphore.cc",
@@ -62,7 +75,6 @@ filegroup {
    srcs: [
        "linux_generic/alarm_unittest.cc",
        "linux_generic/files_test.cc",
        "linux_generic/handler_unittest.cc",
        "linux_generic/queue_unittest.cc",
        "linux_generic/reactor_unittest.cc",
        "linux_generic/repeating_alarm_unittest.cc",
+0 −1
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ source_set("BluetoothOsSources_linux_generic") {
  sources = [
    "linux_generic/alarm.cc",
    "linux_generic/files.cc",
    "linux_generic/handler.cc",
    "linux_generic/reactive_semaphore.cc",
    "linux_generic/reactor.cc",
    "linux_generic/repeating_alarm.cc",
+8 −24
Original line number Diff line number Diff line
@@ -16,9 +16,6 @@

#include "os/handler.h"

#include <sys/eventfd.h>
#include <unistd.h>

#include <cstring>

#include "common/bind.h"
@@ -27,19 +24,14 @@
#include "os/reactor.h"
#include "os/utils.h"

#ifndef EFD_SEMAPHORE
#define EFD_SEMAPHORE 1
#endif

namespace bluetooth {
namespace os {
using common::OnceClosure;

Handler::Handler(Thread* thread)
    : tasks_(new std::queue<OnceClosure>()), thread_(thread), fd_(eventfd(0, EFD_SEMAPHORE | EFD_NONBLOCK)) {
  ASSERT(fd_ != -1);
Handler::Handler(Thread* thread) : tasks_(new std::queue<OnceClosure>()), thread_(thread) {
  event_ = thread_->GetReactor()->NewEvent();
  reactable_ = thread_->GetReactor()->Register(
      fd_, common::Bind(&Handler::handle_next_event, common::Unretained(this)), common::Closure());
      event_->Id(), common::Bind(&Handler::handle_next_event, common::Unretained(this)), common::Closure());
}

Handler::~Handler() {
@@ -47,10 +39,7 @@ Handler::~Handler() {
    std::lock_guard<std::mutex> lock(mutex_);
    ASSERT_LOG(was_cleared(), "Handlers must be cleared before they are destroyed");
  }

  int close_status;
  RUN_NO_INTR(close_status = close(fd_));
  ASSERT(close_status != -1);
  event_->Close();
}

void Handler::Post(OnceClosure closure) {
@@ -62,9 +51,7 @@ void Handler::Post(OnceClosure closure) {
    }
    tasks_->emplace(std::move(closure));
  }
  uint64_t val = 1;
  auto write_result = eventfd_write(fd_, val);
  ASSERT(write_result != -1);
  event_->Notify();
}

void Handler::Clear() {
@@ -76,9 +63,7 @@ void Handler::Clear() {
  }
  delete tmp;

  uint64_t val;
  while (eventfd_read(fd_, &val) == 0) {
  }
  event_->Clear();

  thread_->GetReactor()->Unregister(reactable_);
  reactable_ = nullptr;
@@ -93,13 +78,12 @@ void Handler::handle_next_event() {
  common::OnceClosure closure;
  {
    std::lock_guard<std::mutex> lock(mutex_);
    uint64_t val = 0;
    auto read_result = eventfd_read(fd_, &val);
    bool has_data = event_->Read();

    if (was_cleared()) {
      return;
    }
    ASSERT_LOG(read_result != -1, "eventfd read error %d %s", errno, strerror(errno));
    ASSERT_LOG(has_data, "Notified for work but no work available");

    closure = std::move(tasks_->front());
    tasks_->pop();
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ class Handler : public common::IPostableContext {
  };
  std::queue<common::OnceClosure>* tasks_;
  Thread* thread_;
  int fd_;
  std::unique_ptr<Reactor::Event> event_;
  Reactor::Reactable* reactable_;
  mutable std::mutex mutex_;
  void handle_next_event();
Loading