Skip to content

Commit ddc4da1

Browse files
committed
---
yaml --- r: 69490 b: refs/heads/auto c: 3f6b4c2 h: refs/heads/master v: v3
1 parent 7bdb46c commit ddc4da1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: cccfa8acc450631fe9520abbe40360927ce1961d
17+
refs/heads/auto: 3f6b4c24ec2234a06632234eaf3014ae0e4adc66
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libstd/rt/comm.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,25 @@ impl<T> PortOne<T> {
180180
}
181181

182182
impl<T> Select for PortOne<T> {
183-
#[inline]
183+
#[inline] #[cfg(not(test))]
184184
fn optimistic_check(&mut self) -> bool {
185185
unsafe { (*self.packet()).state.load(Acquire) == STATE_ONE }
186186
}
187187

188+
#[inline] #[cfg(test)]
189+
fn optimistic_check(&mut self) -> bool {
190+
// The optimistic check is never necessary for correctness. For testing
191+
// purposes, making it randomly return false simulates a racing sender.
192+
use rand::{Rand, rng};
193+
let mut rng = rng();
194+
let actually_check = Rand::rand(&mut rng);
195+
if actually_check {
196+
unsafe { (*self.packet()).state.load(Acquire) == STATE_ONE }
197+
} else {
198+
false
199+
}
200+
}
201+
188202
fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool {
189203
unsafe {
190204
// Atomically swap the task pointer into the Packet state, issuing

0 commit comments

Comments
 (0)