Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: runtime/bin/eventhandler_fuchsia.cc

Issue 2468423002: Update usage of mx_handle_wait_many() API. (Closed)
Patch Set: Update usage of mx_handle_wait_many() API. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« runtime/bin/eventhandler_fuchsia.h ('K') | « runtime/bin/eventhandler_fuchsia.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/eventhandler_fuchsia.cc
diff --git a/runtime/bin/eventhandler_fuchsia.cc b/runtime/bin/eventhandler_fuchsia.cc
index 4b325466c102f27881509ef92e70c3f6a8f619d2..6439766178380d8a672a3ce7fca13f416cc87363 100644
--- a/runtime/bin/eventhandler_fuchsia.cc
+++ b/runtime/bin/eventhandler_fuchsia.cc
@@ -36,29 +36,17 @@ MagentaWaitManyInfo::MagentaWaitManyInfo()
if (descriptor_infos_ == NULL) {
FATAL("Failed to allocate descriptor_infos array");
}
- handles_ = static_cast<mx_handle_t*>(
- malloc(kInitialCapacity * sizeof(*handles_)));
- if (handles_ == NULL) {
- FATAL("Failed to allocate handles array");
- }
- signals_ = static_cast<mx_signals_t*>(
- malloc(kInitialCapacity * sizeof(*signals_)));
- if (signals_ == NULL) {
- FATAL("Failed to allocate signals array");
- }
- signals_states_ = static_cast<mx_signals_state_t*>(
- malloc(kInitialCapacity * sizeof(*signals_states_)));
- if (signals_states_ == NULL) {
- FATAL("Failed to allocate signals_states array");
+ items_ = static_cast<mx_wait_item_t*>(
+ malloc(kInitialCapacity * sizeof(*items_)));
+ if (items_ == NULL) {
+ FATAL("Failed to allocate items array");
}
}
MagentaWaitManyInfo::~MagentaWaitManyInfo() {
free(descriptor_infos_);
- free(handles_);
- free(signals_);
- free(signals_states_);
+ free(items_);
}
@@ -68,7 +56,7 @@ void MagentaWaitManyInfo::AddHandle(mx_handle_t handle,
#if defined(DEBUG)
// Check that the handle is not already in the list.
for (intptr_t i = 0; i < size_; i++) {
- if (handles_[i] == handle) {
+ if (items_[i].handle == handle) {
FATAL("The handle is already in the list!");
}
}
@@ -76,10 +64,9 @@ void MagentaWaitManyInfo::AddHandle(mx_handle_t handle,
intptr_t new_size = size_ + 1;
GrowArraysIfNeeded(new_size);
descriptor_infos_[size_] = di;
- handles_[size_] = handle;
- signals_[size_] = signals;
- signals_states_[size_].satisfied = MX_SIGNAL_NONE;
- signals_states_[size_].satisfiable = MX_SIGNAL_NONE;
+ items_[size_].handle = handle;
+ items_[size_].waitfor = signals;
+ items_[size_].pending = 0;
size_ = new_size;
LOG_INFO("AddHandle(%ld, %ld, %p), size = %ld\n", handle, signals, di, size_);
}
@@ -88,7 +75,7 @@ void MagentaWaitManyInfo::AddHandle(mx_handle_t handle,
void MagentaWaitManyInfo::RemoveHandle(mx_handle_t handle) {
intptr_t idx;
for (idx = 1; idx < size_; idx++) {
- if (handle == handles_[idx]) {
+ if (handle == items_[idx].handle) {
break;
}
}
@@ -98,15 +85,10 @@ void MagentaWaitManyInfo::RemoveHandle(mx_handle_t handle) {
if (idx != (size_ - 1)) {
descriptor_infos_[idx] = descriptor_infos_[size_ - 1];
- handles_[idx] = handles_[size_ - 1];
- signals_[idx] = signals_[size_ - 1];
- signals_states_[idx] = signals_states_[size_ - 1];
+ items_[idx] = items_[size_ - 1];
}
descriptor_infos_[size_ - 1] = NULL;
- handles_[size_ - 1] = MX_HANDLE_INVALID;
- signals_[size_ - 1] = MX_SIGNAL_NONE;
- signals_states_[size_ - 1].satisfied = MX_SIGNAL_NONE;
- signals_states_[size_ - 1].satisfiable = MX_SIGNAL_NONE;
+ items_[size_ - 1] = {MX_HANDLE_INVALID, 0, 0};
size_ = size_ - 1;
LOG_INFO("RemoveHandle(%ld), size = %ld\n", handle, size_);
}
@@ -122,20 +104,10 @@ void MagentaWaitManyInfo::GrowArraysIfNeeded(intptr_t desired_size) {
if (descriptor_infos_ == NULL) {
FATAL("Failed to grow descriptor_infos array");
}
- handles_ = static_cast<mx_handle_t*>(
- realloc(handles_, new_capacity * sizeof(*handles_)));
- if (handles_ == NULL) {
- FATAL("Failed to grow handles array");
- }
- signals_ = static_cast<mx_signals_t*>(
- realloc(signals_, new_capacity * sizeof(*signals_)));
- if (signals_ == NULL) {
- FATAL("Failed to grow signals array");
- }
- signals_states_ = static_cast<mx_signals_state_t*>(
- realloc(signals_states_, new_capacity * sizeof(*signals_states_)));
- if (signals_states_ == NULL) {
- FATAL("Failed to grow signals_states array");
+ items_ = static_cast<mx_wait_item_t*>(
+ realloc(items_, new_capacity * sizeof(*items_)));
+ if (items_ == NULL) {
+ FATAL("Failed to grow items array");
}
capacity_ = new_capacity;
LOG_INFO("GrowArraysIfNeeded(%ld), capacity = %ld\n",
@@ -223,7 +195,8 @@ void EventHandlerImplementation::HandleInterruptFd() {
void EventHandlerImplementation::HandleEvents() {
LOG_INFO("HandleEvents entry\n");
for (intptr_t i = 1; i < info_.size(); i++) {
- if (info_.signals_states()[i].satisfied != MX_SIGNAL_NONE) {
+ const mx_wait_item_t& wait_item = info_.items()[i];
+ if (wait_item.pending & wait_item.waitfor) {
// Only the control handle has no descriptor info.
ASSERT(info_.descriptor_infos()[i] != NULL);
ASSERT(info_.handles()[i] != interrupt_handles_[0]);
@@ -233,10 +206,10 @@ void EventHandlerImplementation::HandleEvents() {
}
}
- if ((info_.signals_states()[0].satisfied & MX_SIGNAL_PEER_CLOSED) != 0) {
+ if ((info_.items()[0].pending & MX_SIGNAL_PEER_CLOSED) != 0) {
FATAL("EventHandlerImplementation::Poll: Unexpected peer closed\n");
}
- if ((info_.signals_states()[0].satisfied & MX_SIGNAL_READABLE) != 0) {
+ if ((info_.items()[0].pending & MX_SIGNAL_READABLE) != 0) {
LOG_INFO("HandleEvents interrupt_handles_[0] readable\n");
HandleInterruptFd();
} else {
@@ -278,17 +251,12 @@ void EventHandlerImplementation::Poll(uword args) {
mx_time_t timeout =
millis * kMicrosecondsPerMillisecond * kNanosecondsPerMicrosecond;
const MagentaWaitManyInfo& info = handler_impl->info();
- uint32_t result_index;
- LOG_INFO("mx_handle_wait_many(%ld, %p, %p, %lld, %p, %p)\n",
- info.size(), info.handles(), info.signals(), timeout, &result_index,
- info.signals_states());
+ LOG_INFO("mx_handle_wait_many(%p, %ld, %lld)\n",
+ info.items(), info.size(), timeout);
mx_status_t status = mx_handle_wait_many(
+ info.items(),
info.size(),
- info.handles(),
- info.signals(),
- timeout,
- &result_index,
- info.signals_states());
+ timeout);
if ((status != NO_ERROR) && (status != ERR_TIMED_OUT)) {
FATAL1("mx_handle_wait_many failed: %s\n", mx_status_get_string(status));
} else {
« runtime/bin/eventhandler_fuchsia.h ('K') | « runtime/bin/eventhandler_fuchsia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698