fix(tests): improve atomic data access

This commit is contained in:
Aram Drevekenin 2020-11-26 11:15:35 +01:00
parent 356b9d602b
commit 4f2536a94d

View file

@ -46,7 +46,7 @@ impl FakeStdinReader {
impl Read for FakeStdinReader { impl Read for FakeStdinReader {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
loop { loop {
if self.started_reading_from_pty.load(Ordering::SeqCst) == false { if self.started_reading_from_pty.load(Ordering::Acquire) == false {
::std::thread::sleep(MIN_TIME_BETWEEN_SNAPSHOTS); ::std::thread::sleep(MIN_TIME_BETWEEN_SNAPSHOTS);
} else { } else {
let last_snapshot_time = { *self.last_snapshot_time.lock().unwrap() }; let last_snapshot_time = { *self.last_snapshot_time.lock().unwrap() };
@ -213,7 +213,7 @@ impl OsApi for FakeInputOutput {
// them fail // them fail
::std::thread::sleep(::std::time::Duration::from_millis(25)); ::std::thread::sleep(::std::time::Duration::from_millis(25));
} else if attempts_left == 0 { } else if attempts_left == 0 {
self.started_reading_from_pty.store(true, Ordering::SeqCst); self.started_reading_from_pty.store(true, Ordering::Release);
return Ok(0); return Ok(0);
} }
let mut read_buffers = self.read_buffers.lock().unwrap(); let mut read_buffers = self.read_buffers.lock().unwrap();
@ -227,7 +227,7 @@ impl OsApi for FakeInputOutput {
if bytes_read > bytes.read_position { if bytes_read > bytes.read_position {
bytes.set_read_position(bytes_read); bytes.set_read_position(bytes_read);
} }
self.started_reading_from_pty.store(true, Ordering::SeqCst); self.started_reading_from_pty.store(true, Ordering::Release);
return Ok(bytes_read); return Ok(bytes_read);
} }
None => { None => {