Loading system/gd/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -183,6 +183,7 @@ cc_defaults { ":BluetoothL2capSources", ":BluetoothMetricsSources", ":BluetoothNeighborSources", ":BluetoothOsSources", ":BluetoothPacketSources", ":BluetoothShimSources", ":BluetoothSecuritySources", Loading Loading @@ -354,6 +355,7 @@ cc_test { ":BluetoothHciUnitTestSources", ":BluetoothL2capUnitTestSources", ":BluetoothMetricsTestSources", ":BluetoothOsTestSources", ":BluetoothPacketTestSources", ":BluetoothShimTestSources", ":BluetoothSecurityUnitTestSources", Loading system/gd/os/Android.bp +14 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,13 @@ package { default_applicable_licenses: ["system_bt_license"], } filegroup { name: "BluetoothOsSources", srcs: [ "handler.cc", ], } filegroup { name: "BluetoothOsSources_android", srcs: [ Loading Loading @@ -35,6 +42,13 @@ filegroup { ], } filegroup { name: "BluetoothOsTestSources", srcs: [ "handler_unittest.cc", ], } filegroup { name: "BluetoothOsTestSources_host", srcs: [ Loading @@ -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", Loading @@ -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", Loading system/gd/os/BUILD.gn +0 −1 Original line number Diff line number Diff line Loading @@ -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", Loading system/gd/os/linux_generic/handler.cc→system/gd/os/handler.cc +8 −24 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ #include "os/handler.h" #include <sys/eventfd.h> #include <unistd.h> #include <cstring> #include "common/bind.h" Loading @@ -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() { Loading @@ -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) { Loading @@ -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() { Loading @@ -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; Loading @@ -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(); Loading system/gd/os/handler.h +1 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
system/gd/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -183,6 +183,7 @@ cc_defaults { ":BluetoothL2capSources", ":BluetoothMetricsSources", ":BluetoothNeighborSources", ":BluetoothOsSources", ":BluetoothPacketSources", ":BluetoothShimSources", ":BluetoothSecuritySources", Loading Loading @@ -354,6 +355,7 @@ cc_test { ":BluetoothHciUnitTestSources", ":BluetoothL2capUnitTestSources", ":BluetoothMetricsTestSources", ":BluetoothOsTestSources", ":BluetoothPacketTestSources", ":BluetoothShimTestSources", ":BluetoothSecurityUnitTestSources", Loading
system/gd/os/Android.bp +14 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,13 @@ package { default_applicable_licenses: ["system_bt_license"], } filegroup { name: "BluetoothOsSources", srcs: [ "handler.cc", ], } filegroup { name: "BluetoothOsSources_android", srcs: [ Loading Loading @@ -35,6 +42,13 @@ filegroup { ], } filegroup { name: "BluetoothOsTestSources", srcs: [ "handler_unittest.cc", ], } filegroup { name: "BluetoothOsTestSources_host", srcs: [ Loading @@ -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", Loading @@ -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", Loading
system/gd/os/BUILD.gn +0 −1 Original line number Diff line number Diff line Loading @@ -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", Loading
system/gd/os/linux_generic/handler.cc→system/gd/os/handler.cc +8 −24 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ #include "os/handler.h" #include <sys/eventfd.h> #include <unistd.h> #include <cstring> #include "common/bind.h" Loading @@ -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() { Loading @@ -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) { Loading @@ -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() { Loading @@ -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; Loading @@ -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(); Loading
system/gd/os/handler.h +1 −1 Original line number Diff line number Diff line Loading @@ -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