Loading adb/fdevent/fdevent.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ #include <inttypes.h> #include <android-base/logging.h> #include <android-base/stringprintf.h> #include <android-base/threads.h> #include "fdevent.h" #include "fdevent_poll.h" Loading @@ -46,6 +48,12 @@ std::string dump_fde(const fdevent* fde) { state.c_str()); } void fdevent_context::CheckMainThread() { if (main_thread_id_) { CHECK_EQ(*main_thread_id_, android::base::GetThreadId()); } } void fdevent_context::Run(std::function<void()> fn) { { std::lock_guard<std::mutex> lock(run_queue_mutex_); Loading adb/fdevent/fdevent.h +5 −2 Original line number Diff line number Diff line Loading @@ -75,8 +75,9 @@ struct fdevent_context { // Implementations should call FlushRunQueue on every iteration. virtual void Loop() = 0; // Assert that the caller is running on the context's main thread. virtual void CheckMainThread() = 0; // Assert that the caller is either running on the context's main thread, or that there is no // active main thread. void CheckMainThread(); // Queue an operation to be run on the main thread. void Run(std::function<void()> fn); Loading @@ -92,6 +93,8 @@ struct fdevent_context { // Run all pending functions enqueued via Run(). void FlushRunQueue() EXCLUDES(run_queue_mutex_); std::optional<uint64_t> main_thread_id_ = std::nullopt; private: std::mutex run_queue_mutex_; std::deque<std::function<void()>> run_queue_ GUARDED_BY(run_queue_mutex_); Loading adb/fdevent/fdevent_poll.cpp +4 −10 Original line number Diff line number Diff line Loading @@ -75,16 +75,9 @@ fdevent_context_poll::fdevent_context_poll() { } fdevent_context_poll::~fdevent_context_poll() { main_thread_valid_ = false; this->Destroy(this->interrupt_fde_); } void fdevent_context_poll::CheckMainThread() { if (main_thread_valid_) { CHECK_EQ(main_thread_id_, android::base::GetThreadId()); } } fdevent* fdevent_context_poll::Create(unique_fd fd, std::variant<fd_func, fd_func2> func, void* arg) { CheckMainThread(); Loading Loading @@ -373,13 +366,12 @@ static void fdevent_check_spin(fdevent_context_poll* ctx, uint64_t cycle) { } void fdevent_context_poll::Loop() { this->main_thread_id_ = android::base::GetThreadId(); this->main_thread_valid_ = true; main_thread_id_ = android::base::GetThreadId(); uint64_t cycle = 0; while (true) { if (terminate_loop_) { return; break; } D("--- --- waiting for events"); Loading @@ -396,6 +388,8 @@ void fdevent_context_poll::Loop() { this->FlushRunQueue(); } main_thread_id_.reset(); } void fdevent_context_poll::TerminateLoop() { Loading adb/fdevent/fdevent_poll.h +0 −4 Original line number Diff line number Diff line Loading @@ -58,8 +58,6 @@ struct fdevent_context_poll : public fdevent_context { virtual void Loop() final; virtual void CheckMainThread() final; virtual void TerminateLoop() final; virtual size_t InstalledCount() final; Loading @@ -71,8 +69,6 @@ struct fdevent_context_poll : public fdevent_context { // That's why we don't need a lock for fdevent. std::unordered_map<int, PollNode> poll_node_map_; std::list<fdevent*> pending_list_; bool main_thread_valid_ = false; uint64_t main_thread_id_ = 0; uint64_t fdevent_id_ = 0; unique_fd interrupt_fd_; Loading Loading
adb/fdevent/fdevent.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ #include <inttypes.h> #include <android-base/logging.h> #include <android-base/stringprintf.h> #include <android-base/threads.h> #include "fdevent.h" #include "fdevent_poll.h" Loading @@ -46,6 +48,12 @@ std::string dump_fde(const fdevent* fde) { state.c_str()); } void fdevent_context::CheckMainThread() { if (main_thread_id_) { CHECK_EQ(*main_thread_id_, android::base::GetThreadId()); } } void fdevent_context::Run(std::function<void()> fn) { { std::lock_guard<std::mutex> lock(run_queue_mutex_); Loading
adb/fdevent/fdevent.h +5 −2 Original line number Diff line number Diff line Loading @@ -75,8 +75,9 @@ struct fdevent_context { // Implementations should call FlushRunQueue on every iteration. virtual void Loop() = 0; // Assert that the caller is running on the context's main thread. virtual void CheckMainThread() = 0; // Assert that the caller is either running on the context's main thread, or that there is no // active main thread. void CheckMainThread(); // Queue an operation to be run on the main thread. void Run(std::function<void()> fn); Loading @@ -92,6 +93,8 @@ struct fdevent_context { // Run all pending functions enqueued via Run(). void FlushRunQueue() EXCLUDES(run_queue_mutex_); std::optional<uint64_t> main_thread_id_ = std::nullopt; private: std::mutex run_queue_mutex_; std::deque<std::function<void()>> run_queue_ GUARDED_BY(run_queue_mutex_); Loading
adb/fdevent/fdevent_poll.cpp +4 −10 Original line number Diff line number Diff line Loading @@ -75,16 +75,9 @@ fdevent_context_poll::fdevent_context_poll() { } fdevent_context_poll::~fdevent_context_poll() { main_thread_valid_ = false; this->Destroy(this->interrupt_fde_); } void fdevent_context_poll::CheckMainThread() { if (main_thread_valid_) { CHECK_EQ(main_thread_id_, android::base::GetThreadId()); } } fdevent* fdevent_context_poll::Create(unique_fd fd, std::variant<fd_func, fd_func2> func, void* arg) { CheckMainThread(); Loading Loading @@ -373,13 +366,12 @@ static void fdevent_check_spin(fdevent_context_poll* ctx, uint64_t cycle) { } void fdevent_context_poll::Loop() { this->main_thread_id_ = android::base::GetThreadId(); this->main_thread_valid_ = true; main_thread_id_ = android::base::GetThreadId(); uint64_t cycle = 0; while (true) { if (terminate_loop_) { return; break; } D("--- --- waiting for events"); Loading @@ -396,6 +388,8 @@ void fdevent_context_poll::Loop() { this->FlushRunQueue(); } main_thread_id_.reset(); } void fdevent_context_poll::TerminateLoop() { Loading
adb/fdevent/fdevent_poll.h +0 −4 Original line number Diff line number Diff line Loading @@ -58,8 +58,6 @@ struct fdevent_context_poll : public fdevent_context { virtual void Loop() final; virtual void CheckMainThread() final; virtual void TerminateLoop() final; virtual size_t InstalledCount() final; Loading @@ -71,8 +69,6 @@ struct fdevent_context_poll : public fdevent_context { // That's why we don't need a lock for fdevent. std::unordered_map<int, PollNode> poll_node_map_; std::list<fdevent*> pending_list_; bool main_thread_valid_ = false; uint64_t main_thread_id_ = 0; uint64_t fdevent_id_ = 0; unique_fd interrupt_fd_; Loading