adb: implement fdevent_reset by constructing a new context.

am: 7adca93fe9

Change-Id: Iefd84fb5453ed757feb3b8431c7b31f99e39541e
This commit is contained in:
Josh Gao 2019-07-09 13:36:59 -07:00 committed by android-build-merger
commit 8935c1c89f
4 changed files with 4 additions and 17 deletions

View file

@ -49,10 +49,11 @@ std::string dump_fde(const fdevent* fde) {
state.c_str());
}
static fdevent_context* g_ambient_fdevent_context = new fdevent_context_poll();
static auto& g_ambient_fdevent_context =
*new std::unique_ptr<fdevent_context>(new fdevent_context_poll());
static fdevent_context* fdevent_get_ambient() {
return g_ambient_fdevent_context;
return g_ambient_fdevent_context.get();
}
fdevent* fdevent_create(int fd, fd_func func, void* arg) {
@ -110,5 +111,5 @@ size_t fdevent_installed_count() {
}
void fdevent_reset() {
return fdevent_get_ambient()->Reset();
g_ambient_fdevent_context.reset(new fdevent_context_poll());
}

View file

@ -79,7 +79,6 @@ struct fdevent_context {
// Test-only functionality:
virtual void TerminateLoop() = 0;
virtual size_t InstalledCount() = 0;
virtual void Reset() = 0;
};
struct fdevent {

View file

@ -458,15 +458,3 @@ void fdevent_context_poll::TerminateLoop() {
size_t fdevent_context_poll::InstalledCount() {
return poll_node_map_.size();
}
void fdevent_context_poll::Reset() {
poll_node_map_.clear();
pending_list_.clear();
std::lock_guard<std::mutex> lock(run_queue_mutex_);
run_queue_notify_fd_.reset();
run_queue_.clear();
main_thread_valid_ = false;
terminate_loop_ = false;
}

View file

@ -62,7 +62,6 @@ struct fdevent_context_poll : public fdevent_context {
virtual void TerminateLoop() final;
virtual size_t InstalledCount() final;
virtual void Reset() final;
// All operations to fdevent should happen only in the main thread.
// That's why we don't need a lock for fdevent.