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

Commit 0a2755c1 authored by Hyundo Moon's avatar Hyundo Moon Committed by Automerger Merge Worker
Browse files

Merge "Alarm: Create timerfd with TFD_NONBLOCK flag" into main am: 21b06d68 am: 00fd1e6f

parents efb99742 00fd1e6f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -407,9 +407,11 @@ cc_test {
        ":BluetoothOsTestSources_timerfd",
    ],
    static_libs: [
        "bluetooth_flags_c_lib_for_test",
        "libbluetooth_log",
        "libchrome",
        "libgmock",
        "server_configurable_flags",
    ],
    shared_libs: [
        "libbase",
@@ -733,6 +735,7 @@ cc_fuzz {
cc_benchmark {
    name: "bluetooth_benchmark_gd",
    defaults: [
        "aconfig_lib_cc_shared_link.defaults",
        "gd_defaults",
    ],
    host_supported: true,
@@ -741,12 +744,14 @@ cc_benchmark {
        "benchmark.cc",
    ],
    static_libs: [
        "bluetooth_flags_c_lib",
        "libbase",
        "libbluetooth_gd",
        "libbluetooth_log",
        "libbt_shim_bridge",
        "libchrome",
        "liblog",
        "server_configurable_flags",
    ],
}

+4 −1
Original line number Diff line number Diff line
@@ -66,7 +66,10 @@ source_set("BluetoothOsSources_linux_generic") {
    "//bt/system/gd:gd_defaults",
    "//bt/system/log:log_defaults",
  ]
  deps = [ "//bt/system/gd:gd_default_deps" ]
  deps = [
    "//bt/flags:bluetooth_flags_c_lib",
    "//bt/system/gd:gd_default_deps",
  ]

  if (target_os == "chromeos") {
    deps += [ ":BluetoothOsSources_chromeos" ]
+15 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "os/alarm.h"

#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>
#include <sys/timerfd.h>
#include <unistd.h>

@@ -38,7 +39,11 @@ namespace os {
using common::Closure;
using common::OnceClosure;

Alarm::Alarm(Handler* handler) : handler_(handler), fd_(TIMERFD_CREATE(ALARM_CLOCK, 0)) {
Alarm::Alarm(Handler* handler) : handler_(handler) {
  int timerfd_flag =
          com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation() ? TFD_NONBLOCK : 0;
  fd_ = TIMERFD_CREATE(ALARM_CLOCK, timerfd_flag);

  log::assert_that(fd_ != -1, "cannot create timerfd: {}", strerror(errno));

  token_ = handler_->thread_->GetReactor()->Register(
@@ -77,6 +82,15 @@ void Alarm::on_fire() {
  uint64_t times_invoked;
  auto bytes_read = read(fd_, &times_invoked, sizeof(uint64_t));
  lock.unlock();

  if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation() && bytes_read == -1) {
    log::info("No data to read.");
    if (errno == EAGAIN || errno == EWOULDBLOCK) {
      log::info("Alarm is already canceled or rescheduled.");
      return;
    }
  }

  log::assert_that(bytes_read == static_cast<ssize_t>(sizeof(uint64_t)),
                   "assert failed: bytes_read == static_cast<ssize_t>(sizeof(uint64_t))");
  log::assert_that(times_invoked == static_cast<uint64_t>(1), "Invoked number of times:{} fd:{}",