Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve performance and space of async_std::sync::Mutex#370

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
nbdd0121 wants to merge10 commits intoasync-rs:masterfromnbdd0121:mutex
Closed
Changes from1 commit
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
Retry locking the mutex before touching waker list.
Moving the try_lock code to before touching the waker list issound, because the waker list can only ever be accessed with `blocked`hold, so as long as we retry lock it while having `blocked` locked, weare okay.This code also set both LOCK and BLOCKED in the same atomic op. Thishas some performance improvements by touching the atomic variable 1less time when inserting the entry.Signed-off-by: Gary Guo <gary@garyguo.net>
  • Loading branch information
@nbdd0121
nbdd0121 committedOct 21, 2019
commit7855b900c9a9f6a889c32ff91ff6621bc095bd62
23 changes: 10 additions & 13 deletionssrc/sync/mutex.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,13 +111,18 @@ impl<'a> Future for RawLockFuture<'a> {
} else {
let mut blocked = self.mutex.blocked.lock();

// Try locking again because it's possible the mutex got unlocked before
// we acquire the lock of `blocked`.
let state = self.mutex.state.fetch_or(LOCK | BLOCKED, Ordering::Relaxed);
if state & LOCK == 0 {
std::mem::drop(blocked);
self.deregister_waker(true);
return Poll::Ready(())
}

// Register the current task.
match self.opt_key {
None => {
if blocked.is_empty() {
self.mutex.state.fetch_or(BLOCKED, Ordering::Relaxed);
}

// Insert a new entry into the list of blocked tasks.
let w = cx.waker().clone();
let key = blocked.insert(Some(w));
Expand All@@ -134,15 +139,7 @@ impl<'a> Future for RawLockFuture<'a> {
}
}

// Try locking again because it's possible the mutex got unlocked just
// before the current task was registered as a blocked task.
if self.mutex.try_lock() {
std::mem::drop(blocked);
self.deregister_waker(true);
Poll::Ready(())
} else {
Poll::Pending
}
Poll::Pending
}
}
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp