Skip to content

Commit 0661f77

Browse files
committed
Merge branch 'master' into add_stdin_lock
2 parents caa2338 + a3b7421 commit 0661f77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1190
-1117
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,10 @@ jobs:
5252
steps:
5353
- uses: actions/checkout@master
5454

55-
- id: component
56-
uses: actions-rs/components-nightly@v1
57-
with:
58-
component: rustfmt
59-
6055
- uses: actions-rs/toolchain@v1
6156
with:
6257
profile: minimal
63-
toolchain: ${{ steps.component.outputs.toolchain }}
58+
toolchain: nightly
6459
override: true
6560
components: rustfmt
6661

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ unstable = ["broadcaster"]
2727
[dependencies]
2828
async-macros = "1.0.0"
2929
async-task = "1.0.0"
30+
broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] }
3031
crossbeam-channel = "0.3.9"
3132
crossbeam-deque = "0.7.1"
3233
crossbeam-utils = "0.6.6"
3334
futures-core-preview = "=0.3.0-alpha.19"
3435
futures-io-preview = "=0.3.0-alpha.19"
3536
futures-timer = "1.0.2"
37+
kv-log-macro = "1.0.4"
3638
log = { version = "0.4.8", features = ["kv_unstable"] }
3739
memchr = "2.2.1"
3840
mio = "0.6.19"
3941
mio-uds = "0.6.7"
4042
num_cpus = "1.10.1"
4143
once_cell = "1.2.0"
44+
pin-project-lite = "0.1"
4245
pin-utils = "0.1.0-alpha.4"
4346
slab = "0.4.2"
44-
kv-log-macro = "1.0.4"
45-
broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] }
46-
pin-project-lite = "0.1"
4747

4848
[dev-dependencies]
4949
femme = "1.2.0"

benches/mutex.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(test)]
2+
3+
extern crate test;
4+
5+
use std::sync::Arc;
6+
7+
use async_std::sync::Mutex;
8+
use async_std::task;
9+
use test::Bencher;
10+
11+
#[bench]
12+
fn create(b: &mut Bencher) {
13+
b.iter(|| Mutex::new(()));
14+
}
15+
16+
#[bench]
17+
fn contention(b: &mut Bencher) {
18+
b.iter(|| task::block_on(run(10, 1000)));
19+
}
20+
21+
#[bench]
22+
fn no_contention(b: &mut Bencher) {
23+
b.iter(|| task::block_on(run(1, 10000)));
24+
}
25+
26+
async fn run(task: usize, iter: usize) {
27+
let m = Arc::new(Mutex::new(()));
28+
let mut tasks = Vec::new();
29+
30+
for _ in 0..task {
31+
let m = m.clone();
32+
tasks.push(task::spawn(async move {
33+
for _ in 0..iter {
34+
let _ = m.lock().await;
35+
}
36+
}));
37+
}
38+
39+
for t in tasks {
40+
t.await;
41+
}
42+
}

benches/task.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(test)]
2+
3+
extern crate test;
4+
5+
use async_std::task;
6+
use test::Bencher;
7+
8+
#[bench]
9+
fn block_on(b: &mut Bencher) {
10+
b.iter(|| task::block_on(async {}));
11+
}

src/fs/canonicalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::io;
22
use crate::path::{Path, PathBuf};
3-
use crate::task::blocking;
3+
use crate::task::spawn_blocking;
44

55
/// Returns the canonical form of a path.
66
///
@@ -32,5 +32,5 @@ use crate::task::blocking;
3232
/// ```
3333
pub async fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
3434
let path = path.as_ref().to_owned();
35-
blocking::spawn(move || std::fs::canonicalize(&path).map(Into::into)).await
35+
spawn_blocking(move || std::fs::canonicalize(&path).map(Into::into)).await
3636
}

src/fs/copy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::io;
22
use crate::path::Path;
3-
use crate::task::blocking;
3+
use crate::task::spawn_blocking;
44

55
/// Copies the contents and permissions of a file to a new location.
66
///
@@ -41,5 +41,5 @@ use crate::task::blocking;
4141
pub async fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
4242
let from = from.as_ref().to_owned();
4343
let to = to.as_ref().to_owned();
44-
blocking::spawn(move || std::fs::copy(&from, &to)).await
44+
spawn_blocking(move || std::fs::copy(&from, &to)).await
4545
}

src/fs/create_dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::io;
22
use crate::path::Path;
3-
use crate::task::blocking;
3+
use crate::task::spawn_blocking;
44

55
/// Creates a new directory.
66
///
@@ -34,5 +34,5 @@ use crate::task::blocking;
3434
/// ```
3535
pub async fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
3636
let path = path.as_ref().to_owned();
37-
blocking::spawn(move || std::fs::create_dir(path)).await
37+
spawn_blocking(move || std::fs::create_dir(path)).await
3838
}

src/fs/create_dir_all.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::io;
22
use crate::path::Path;
3-
use crate::task::blocking;
3+
use crate::task::spawn_blocking;
44

55
/// Creates a new directory and all of its parents if they are missing.
66
///
@@ -29,5 +29,5 @@ use crate::task::blocking;
2929
/// ```
3030
pub async fn create_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
3131
let path = path.as_ref().to_owned();
32-
blocking::spawn(move || std::fs::create_dir_all(path)).await
32+
spawn_blocking(move || std::fs::create_dir_all(path)).await
3333
}

src/fs/dir_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::future::Future;
22

33
use crate::io;
44
use crate::path::Path;
5-
use crate::task::blocking;
5+
use crate::task::spawn_blocking;
66

77
/// A builder for creating directories with configurable options.
88
///
@@ -107,7 +107,7 @@ impl DirBuilder {
107107
}
108108

109109
let path = path.as_ref().to_owned();
110-
async move { blocking::spawn(move || builder.create(path)).await }
110+
async move { spawn_blocking(move || builder.create(path)).await }
111111
}
112112
}
113113

src/fs/dir_entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55
use crate::fs::{FileType, Metadata};
66
use crate::io;
77
use crate::path::PathBuf;
8-
use crate::task::blocking;
8+
use crate::task::spawn_blocking;
99

1010
/// An entry in a directory.
1111
///
@@ -87,7 +87,7 @@ impl DirEntry {
8787
/// ```
8888
pub async fn metadata(&self) -> io::Result<Metadata> {
8989
let inner = self.0.clone();
90-
blocking::spawn(move || inner.metadata()).await
90+
spawn_blocking(move || inner.metadata()).await
9191
}
9292

9393
/// Reads the file type for this entry.
@@ -125,7 +125,7 @@ impl DirEntry {
125125
/// ```
126126
pub async fn file_type(&self) -> io::Result<FileType> {
127127
let inner = self.0.clone();
128-
blocking::spawn(move || inner.file_type()).await
128+
spawn_blocking(move || inner.file_type()).await
129129
}
130130

131131
/// Returns the bare name of this entry without the leading path.

0 commit comments

Comments
 (0)