Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for poll-based backend #1687

Merged
merged 24 commits into from
Jul 31, 2023
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a6edda7
Implement poll-based backend
jasta Jul 7, 2023
496bc0e
Fixed syntax error in ci workflow
jasta Jul 24, 2023
2889557
Fix build break with --no-default-features --features net
jasta Jul 25, 2023
1813a63
Fix mio_unsupported_force_poll_poll release builds
jasta Jul 25, 2023
cfc13bc
Fix non-conforming usage of log::trace
jasta Jul 25, 2023
ca576a5
Run rustfmt
jasta Jul 25, 2023
ad3cc96
Update src/sys/unix/selector/poll.rs
jasta Jul 26, 2023
4b8a935
poll: Optimize register corner case
jasta Jul 26, 2023
037a538
poll: Slight change to error message consistency
jasta Jul 26, 2023
5fda03c
poll: Fix event copy/paste debug_details formatting
jasta Jul 26, 2023
f7d0885
poll: Manually fix missing rustfmt case
jasta Jul 26, 2023
a4c72a8
poll: Fix try_clone not carrying has_waker state forward
jasta Jul 26, 2023
1de715c
poll: Simplify and optimize pending_wake_tokens to use a singular Token
jasta Jul 26, 2023
0ce239e
poll: No longer special case poll returning 0 and redundantly checkin…
jasta Jul 26, 2023
e15d449
poll: Copy timeout determination logic from epoll impl
jasta Jul 26, 2023
c61d221
poll: Clarify nested poll loop behaviour slightly
jasta Jul 26, 2023
fa88f19
poll: Further clarify nested poll loop behaviour
jasta Jul 26, 2023
185dbf5
poll: rename notified_events for consistency
jasta Jul 26, 2023
71c635f
poll: Minor documentation for pending_wake_token behaviour
jasta Jul 26, 2023
0970313
poll: Document design choice quirks in comments
jasta Jul 30, 2023
fc0a153
poll: Avoid early return on error in deregister_all
jasta Jul 30, 2023
8570ec9
poll: Rerun rustfmt
jasta Jul 30, 2023
189a117
poll: Fix target_os="wasi" compilation error
jasta Jul 30, 2023
a7c41ee
poll: Fix MSRV by not using std::os::fd
jasta Jul 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
poll: Simplify and optimize pending_wake_tokens to use a singular Token
jasta committed Jul 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1de715cb653095c38bcdd1cf60b68e087c78e51f
21 changes: 9 additions & 12 deletions src/sys/unix/selector/poll.rs
Original file line number Diff line number Diff line change
@@ -107,10 +107,10 @@ struct SelectorState {
/// out all removed descriptors after that poll is finished running.
pending_removal: Mutex<Vec<RawFd>>,

/// Tokens associated with Wakers that have recently asked to wake. This will
/// Token associated with Waker that have recently asked to wake. This will
/// cause a synthetic behaviour where on any wakeup we add all pending tokens
/// to the list of emitted events.
pending_wake_tokens: Mutex<Vec<Token>>,
pending_wake_token: Mutex<Option<Token>>,

/// Data is written to this to wake up the current instance of `wait`, which can occur when the
/// user notifies it (in which case `notified` would have been set) or when an operation needs
@@ -187,7 +187,7 @@ impl SelectorState {
fd_data: HashMap::new(),
}),
pending_removal: Mutex::new(Vec::new()),
pending_wake_tokens: Mutex::new(Vec::new()),
pending_wake_token: Mutex::new(None),
notify_waker,
waiting_operations: AtomicUsize::new(0),
operations_complete: Condvar::new(),
@@ -227,14 +227,13 @@ impl SelectorState {
let notified = notified_events != 0;
let mut num_fd_events = if notified { num_events - 1 } else { num_events };

let mut pending_wake_tokens_guard = self.pending_wake_tokens.lock().unwrap();
let pending_wake_tokens =
std::mem::replace(pending_wake_tokens_guard.as_mut(), Vec::new());
drop(pending_wake_tokens_guard);
let pending_wake_token = self.pending_wake_token.lock().unwrap().take();

if notified {
self.notify_waker.ack_and_reset();
num_fd_events += pending_wake_tokens.len();
if pending_wake_token.is_some() {
num_fd_events += 1;
}
}

// We now check whether this poll was performed with descriptors which were pending
@@ -249,7 +248,7 @@ impl SelectorState {

events.reserve(num_fd_events);

for pending_wake_token in pending_wake_tokens {
if let Some(pending_wake_token) = pending_wake_token {
events.push(Event {
token: pending_wake_token,
events: notified_events,
@@ -430,9 +429,7 @@ impl SelectorState {
}

pub fn wake(&self, token: Token) -> io::Result<()> {
let mut pending_wake_tokens = self.pending_wake_tokens.lock().unwrap();
pending_wake_tokens.push(token);
drop(pending_wake_tokens);
self.pending_wake_token.lock().unwrap().replace(token);
self.notify_waker.wake()
}
}