mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
More robust file implementation
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
This commit is contained in:
parent
98d9284e64
commit
17c95a39d7
4 changed files with 466 additions and 457 deletions
|
@ -27,10 +27,9 @@ unstable = []
|
||||||
async-task = "1.0.0"
|
async-task = "1.0.0"
|
||||||
cfg-if = "0.1.9"
|
cfg-if = "0.1.9"
|
||||||
crossbeam-channel = "0.3.9"
|
crossbeam-channel = "0.3.9"
|
||||||
futures-channel-preview = "0.3.0-alpha.18"
|
|
||||||
futures-core-preview = "0.3.0-alpha.18"
|
futures-core-preview = "0.3.0-alpha.18"
|
||||||
futures-io-preview = "0.3.0-alpha.18"
|
futures-io-preview = "0.3.0-alpha.18"
|
||||||
futures-timer = "0.3.0"
|
futures-timer = "0.4.0"
|
||||||
lazy_static = "1.3.0"
|
lazy_static = "1.3.0"
|
||||||
log = { version = "0.4.8", features = ["kv_unstable"] }
|
log = { version = "0.4.8", features = ["kv_unstable"] }
|
||||||
memchr = "2.2.1"
|
memchr = "2.2.1"
|
||||||
|
|
|
@ -7,7 +7,7 @@ use async_std::io;
|
||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
|
|
||||||
const LEN: usize = 4 * 1024 * 1024; // 4 Mb
|
const LEN: usize = 16 * 1024; // 16 Kb
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let path = args().nth(1).expect("missing path argument");
|
let path = args().nth(1).expect("missing path argument");
|
||||||
|
|
900
src/fs/file.rs
900
src/fs/file.rs
File diff suppressed because it is too large
Load diff
|
@ -213,7 +213,11 @@ impl<T: Evented> IoHandle<T> {
|
||||||
let mut readiness = mio::Ready::from_usize(self.entry.readiness.load(Ordering::SeqCst));
|
let mut readiness = mio::Ready::from_usize(self.entry.readiness.load(Ordering::SeqCst));
|
||||||
|
|
||||||
if (readiness & mask).is_empty() {
|
if (readiness & mask).is_empty() {
|
||||||
self.entry.readers.lock().unwrap().push(cx.waker().clone());
|
let mut list = self.entry.readers.lock().unwrap();
|
||||||
|
if list.iter().all(|w| !w.will_wake(cx.waker())) {
|
||||||
|
list.push(cx.waker().clone());
|
||||||
|
}
|
||||||
|
|
||||||
readiness = mio::Ready::from_usize(self.entry.readiness.fetch_or(0, Ordering::SeqCst));
|
readiness = mio::Ready::from_usize(self.entry.readiness.fetch_or(0, Ordering::SeqCst));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +254,11 @@ impl<T: Evented> IoHandle<T> {
|
||||||
let mut readiness = mio::Ready::from_usize(self.entry.readiness.load(Ordering::SeqCst));
|
let mut readiness = mio::Ready::from_usize(self.entry.readiness.load(Ordering::SeqCst));
|
||||||
|
|
||||||
if (readiness & mask).is_empty() {
|
if (readiness & mask).is_empty() {
|
||||||
self.entry.writers.lock().unwrap().push(cx.waker().clone());
|
let mut list = self.entry.writers.lock().unwrap();
|
||||||
|
if list.iter().all(|w| !w.will_wake(cx.waker())) {
|
||||||
|
list.push(cx.waker().clone());
|
||||||
|
}
|
||||||
|
|
||||||
readiness = mio::Ready::from_usize(self.entry.readiness.fetch_or(0, Ordering::SeqCst));
|
readiness = mio::Ready::from_usize(self.entry.readiness.fetch_or(0, Ordering::SeqCst));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue