summaryrefslogtreecommitdiffstats
path: root/tokio/src/sync
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-10-09 10:02:55 -0700
committerGitHub <noreply@github.com>2020-10-09 10:02:55 -0700
commitafe535283c68dec40c5fc7a810445e8c2380880f (patch)
tree41c0271db0ffc39662fac9a0cc957dee216a2bef /tokio/src/sync
parentee597347c5e612611142ece09c79e55f2d243590 (diff)
fs: future proof `File` (#2930)
Changes inherent methods to take `&self` instead of `&mut self`. This brings the API in line with `std`. This patch is implemented by using a `tokio::sync::Mutex` to guard the internal `File` state. This is not an ideal implementation strategy doesn't make a big impact compared to having to dispatch operations to a background thread followed by a blocking syscall. In the future, the implementation can be improved as we explore async file-system APIs provided by the operating-system (iocp / io_uring). Closes #2927
Diffstat (limited to 'tokio/src/sync')
-rw-r--r--tokio/src/sync/batch_semaphore.rs1
-rw-r--r--tokio/src/sync/mod.rs9
-rw-r--r--tokio/src/sync/mutex.rs2
3 files changed, 11 insertions, 1 deletions
diff --git a/tokio/src/sync/batch_semaphore.rs b/tokio/src/sync/batch_semaphore.rs
index d09528be..0b50e4f7 100644
--- a/tokio/src/sync/batch_semaphore.rs
+++ b/tokio/src/sync/batch_semaphore.rs
@@ -1,3 +1,4 @@
+#![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))]
//! # Implementation Details
//!
//! The semaphore is implemented using an intrusive linked list of waiters. An
diff --git a/tokio/src/sync/mod.rs b/tokio/src/sync/mod.rs
index 4919ad8e..ed9f07a0 100644
--- a/tokio/src/sync/mod.rs
+++ b/tokio/src/sync/mod.rs
@@ -456,6 +456,14 @@ cfg_sync! {
}
cfg_not_sync! {
+ #[cfg(any(feature = "fs", feature = "signal", all(unix, feature = "process")))]
+ pub(crate) mod batch_semaphore;
+
+ cfg_fs! {
+ mod mutex;
+ pub(crate) use mutex::Mutex;
+ }
+
mod notify;
pub(crate) use notify::Notify;
@@ -472,7 +480,6 @@ cfg_not_sync! {
cfg_signal_internal! {
pub(crate) mod mpsc;
- pub(crate) mod batch_semaphore;
}
}
diff --git a/tokio/src/sync/mutex.rs b/tokio/src/sync/mutex.rs
index b2cf64d3..21e44ca9 100644
--- a/tokio/src/sync/mutex.rs
+++ b/tokio/src/sync/mutex.rs
@@ -1,3 +1,5 @@
+#![cfg_attr(not(feature = "sync"), allow(unreachable_pub, dead_code))]
+
use crate::sync::batch_semaphore as semaphore;
use std::cell::UnsafeCell;