adb: fdevent: move TerminateLoop to fdevent_context.
Test: adb_test Change-Id: Ib1f20aefdb36603e2ceac4197c02551f557056ee
This commit is contained in:
parent
2c95bf73a5
commit
ebaa348d32
4 changed files with 10 additions and 10 deletions
|
|
@ -63,6 +63,11 @@ void fdevent_context::Run(std::function<void()> fn) {
|
||||||
Interrupt();
|
Interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fdevent_context::TerminateLoop() {
|
||||||
|
terminate_loop_ = true;
|
||||||
|
Interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
void fdevent_context::FlushRunQueue() {
|
void fdevent_context::FlushRunQueue() {
|
||||||
// We need to be careful around reentrancy here, since a function we call can queue up another
|
// We need to be careful around reentrancy here, since a function we call can queue up another
|
||||||
// function.
|
// function.
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,9 @@ struct fdevent_context {
|
||||||
// trigger repeatedly every |timeout| ms.
|
// trigger repeatedly every |timeout| ms.
|
||||||
virtual void SetTimeout(fdevent* fde, std::optional<std::chrono::milliseconds> timeout) = 0;
|
virtual void SetTimeout(fdevent* fde, std::optional<std::chrono::milliseconds> timeout) = 0;
|
||||||
|
|
||||||
// Loop forever, handling events.
|
// Loop until TerminateLoop is called, handling events.
|
||||||
// Implementations should call FlushRunQueue on every iteration.
|
// Implementations should call FlushRunQueue on every iteration, and check the value of
|
||||||
|
// terminate_loop_ to determine whether to stop.
|
||||||
virtual void Loop() = 0;
|
virtual void Loop() = 0;
|
||||||
|
|
||||||
// Assert that the caller is either running on the context's main thread, or that there is no
|
// Assert that the caller is either running on the context's main thread, or that there is no
|
||||||
|
|
@ -83,7 +84,7 @@ struct fdevent_context {
|
||||||
void Run(std::function<void()> fn);
|
void Run(std::function<void()> fn);
|
||||||
|
|
||||||
// Test-only functionality:
|
// Test-only functionality:
|
||||||
virtual void TerminateLoop() = 0;
|
void TerminateLoop();
|
||||||
virtual size_t InstalledCount() = 0;
|
virtual size_t InstalledCount() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -94,6 +95,7 @@ struct fdevent_context {
|
||||||
void FlushRunQueue() EXCLUDES(run_queue_mutex_);
|
void FlushRunQueue() EXCLUDES(run_queue_mutex_);
|
||||||
|
|
||||||
std::optional<uint64_t> main_thread_id_ = std::nullopt;
|
std::optional<uint64_t> main_thread_id_ = std::nullopt;
|
||||||
|
std::atomic<bool> terminate_loop_ = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex run_queue_mutex_;
|
std::mutex run_queue_mutex_;
|
||||||
|
|
|
||||||
|
|
@ -392,11 +392,6 @@ void fdevent_context_poll::Loop() {
|
||||||
main_thread_id_.reset();
|
main_thread_id_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fdevent_context_poll::TerminateLoop() {
|
|
||||||
terminate_loop_ = true;
|
|
||||||
Interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t fdevent_context_poll::InstalledCount() {
|
size_t fdevent_context_poll::InstalledCount() {
|
||||||
// We always have an installed fde for interrupt.
|
// We always have an installed fde for interrupt.
|
||||||
return poll_node_map_.size() - 1;
|
return poll_node_map_.size() - 1;
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ struct fdevent_context_poll : public fdevent_context {
|
||||||
|
|
||||||
virtual void Loop() final;
|
virtual void Loop() final;
|
||||||
|
|
||||||
virtual void TerminateLoop() final;
|
|
||||||
virtual size_t InstalledCount() final;
|
virtual size_t InstalledCount() final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -73,5 +72,4 @@ struct fdevent_context_poll : public fdevent_context {
|
||||||
|
|
||||||
unique_fd interrupt_fd_;
|
unique_fd interrupt_fd_;
|
||||||
fdevent* interrupt_fde_ = nullptr;
|
fdevent* interrupt_fde_ = nullptr;
|
||||||
std::atomic<bool> terminate_loop_ = false;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue