adb: add an id field to fdevent.
Tracking fdevents by pointer is dangerous because an fdevent can be destroyed and recreated at the same address. Add a monotonically increasing id field to fdevent for this purpose. Test: treehugger Change-Id: I706b57a9e669290ef2db258f85489a5155fc1152
This commit is contained in:
parent
e44d38d680
commit
ded557fa58
2 changed files with 8 additions and 1 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "fdevent.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -75,6 +76,8 @@ static std::atomic<bool> terminate_loop(false);
|
|||
static bool main_thread_valid;
|
||||
static uint64_t main_thread_id;
|
||||
|
||||
static uint64_t fdevent_id;
|
||||
|
||||
static bool run_needs_flush = false;
|
||||
static auto& run_queue_notify_fd = *new unique_fd();
|
||||
static auto& run_queue_mutex = *new std::mutex();
|
||||
|
@ -111,7 +114,8 @@ static std::string dump_fde(const fdevent* fde) {
|
|||
if (fde->state & FDE_ERROR) {
|
||||
state += "E";
|
||||
}
|
||||
return android::base::StringPrintf("(fdevent %d %s)", fde->fd.get(), state.c_str());
|
||||
return android::base::StringPrintf("(fdevent %" PRIu64 ": fd %d %s)", fde->id, fde->fd.get(),
|
||||
state.c_str());
|
||||
}
|
||||
|
||||
void fdevent_install(fdevent* fde, int fd, fd_func func, void* arg) {
|
||||
|
@ -125,6 +129,7 @@ fdevent* fdevent_create(int fd, fd_func func, void* arg) {
|
|||
CHECK_GE(fd, 0);
|
||||
|
||||
fdevent* fde = new fdevent();
|
||||
fde->id = fdevent_id++;
|
||||
fde->state = FDE_ACTIVE;
|
||||
fde->fd.reset(fd);
|
||||
fde->func = func;
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
typedef void (*fd_func)(int fd, unsigned events, void *userdata);
|
||||
|
||||
struct fdevent {
|
||||
uint64_t id;
|
||||
|
||||
unique_fd fd;
|
||||
int force_eof = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue