Rewrite XIOCompletion::WaitForNotification
This commit is contained in:
parent
1de47e0d17
commit
9b86132fd0
|
@ -368,8 +368,8 @@ dword_result_t NtRemoveIoCompletion(
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t timeout_ticks = timeout ? static_cast<uint32_t>(*timeout) : 0u;
|
uint64_t timeout_ticks = timeout ? static_cast<uint32_t>(*timeout) : 0u;
|
||||||
if (port->WaitForNotification(timeout_ticks)) {
|
XIOCompletion::IONotification notification;
|
||||||
auto notification = port->DequeueNotification();
|
if (port->WaitForNotification(timeout_ticks, ¬ification)) {
|
||||||
if (key_context) {
|
if (key_context) {
|
||||||
*key_context = notification.key_context;
|
*key_context = notification.key_context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,20 +26,17 @@ void XIOCompletion::QueueNotification(IONotification& notification) {
|
||||||
notification_semaphore_->Release(1, nullptr);
|
notification_semaphore_->Release(1, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
XIOCompletion::IONotification XIOCompletion::DequeueNotification() {
|
bool XIOCompletion::WaitForNotification(uint64_t wait_ticks,
|
||||||
std::unique_lock<std::mutex> lock(notification_lock_);
|
IONotification* notify) {
|
||||||
assert_false(notifications_.empty());
|
|
||||||
|
|
||||||
auto notification = notifications_.front();
|
|
||||||
notifications_.pop();
|
|
||||||
|
|
||||||
return notification;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XIOCompletion::WaitForNotification(uint64_t wait_ticks) {
|
|
||||||
auto ms = std::chrono::milliseconds(TimeoutTicksToMs(wait_ticks));
|
auto ms = std::chrono::milliseconds(TimeoutTicksToMs(wait_ticks));
|
||||||
auto res = threading::Wait(notification_semaphore_.get(), false, ms);
|
auto res = threading::Wait(notification_semaphore_.get(), false, ms);
|
||||||
if (res == threading::WaitResult::kSuccess) {
|
if (res == threading::WaitResult::kSuccess) {
|
||||||
|
std::unique_lock<std::mutex> lock(notification_lock_);
|
||||||
|
assert_false(notifications_.empty());
|
||||||
|
|
||||||
|
std::memcpy(notify, ¬ifications_.front(), sizeof(IONotification));
|
||||||
|
notifications_.pop();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,9 @@ class XIOCompletion : public XObject {
|
||||||
};
|
};
|
||||||
|
|
||||||
void QueueNotification(IONotification& notification);
|
void QueueNotification(IONotification& notification);
|
||||||
IONotification DequeueNotification();
|
|
||||||
|
|
||||||
// If you call this and it returns true, you MUST dequeue a notification!
|
// Returns true if the wait ended because a notification was received.
|
||||||
// Returns true if the wait was cancelled because a notification was queued.
|
bool WaitForNotification(uint64_t wait_ticks, IONotification* notify);
|
||||||
bool WaitForNotification(uint64_t wait_ticks);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const uint32_t kMaxNotifications = 1024;
|
static const uint32_t kMaxNotifications = 1024;
|
||||||
|
|
Loading…
Reference in New Issue