Skip to content

Commit

Permalink
Rewrite mpsc::shared
Browse files Browse the repository at this point in the history
Previous version had too much state: `cnt`, `steals`, `port_dropped`
fields, and it's too hard to consistently update all of them during
upgrade.  I tried to fix issue rust-lang#39364, but there are too many corner
cases.  In this version all of these fields removed, and shared
state is basically managed by two fields: `queue` and `to_wait`.

`to_wake` field now stores both `SignalToken` and "disconnected"
flag.

All tests still pass, and bug rust-lang#39364 no longer reproduces.

Patch includes a couple of stress tests.

This version should have the same performance characteristics,
because roughly the same number of atomics and wait/notify operations
involved.
  • Loading branch information
stepancheg committed Jun 22, 2017
1 parent 29bce6e commit 6998b3c
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 267 deletions.
13 changes: 13 additions & 0 deletions src/libstd/sync/mpsc/mpsc_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ impl<T> Queue<T> {
if self.head.load(Ordering::Acquire) == tail {Empty} else {Inconsistent}
}
}

pub fn can_pop(&self) -> bool {
unsafe {
let tail = *self.tail.get();
let next = (*tail).next.load(Ordering::Acquire);

if !next.is_null() {
true
} else {
self.head.load(Ordering::Acquire) != tail
}
}
}
}

impl<T> Drop for Queue<T> {
Expand Down
Loading

0 comments on commit 6998b3c

Please sign in to comment.