Skip to content

Commit 0c03384

Browse files
committed
Move over to using parking_lot for all locks
1 parent 33d842c commit 0c03384

29 files changed

Lines changed: 106 additions & 121 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ libc = "0.2.186"
6161
libloading = "0.9.0"
6262
lsp-types = "0.97.0"
6363
ninep = { version = "0.6", path = "crates/ninep", default-features = false }
64+
parking_lot = "0.12.5"
6465
serde = "1.0.228"
6566
serde_json = "1.0.149"
6667
structex = { version = "0.6", default-features = false }

benches/benchmarks/ts_update.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
use ad_editor::{Config, buffer::Buffer, dot::TextObject, editor::Action};
33
use ad_event::Source;
44
use criterion::{Criterion, criterion_group};
5-
use std::{
6-
env::current_dir,
7-
sync::{Arc, RwLock},
8-
};
5+
use parking_lot::RwLock;
6+
use std::{env::current_dir, sync::Arc};
97

108
fn criterion_benchmark(c: &mut Criterion) {
119
let mut group = c.benchmark_group("TS update");

benches/benchmarks/tui_render.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use ad_editor::{
66
ui::{GenericTui, Layout, UserInterface},
77
};
88
use criterion::{BenchmarkGroup, Criterion, criterion_group, measurement::WallTime};
9+
use parking_lot::RwLock;
910
use std::{
1011
env::current_dir,
1112
hint::black_box,
1213
io::{self, Write},
13-
sync::{Arc, RwLock},
14+
sync::Arc,
1415
};
1516

1617
fn criterion_benchmark(c: &mut Criterion) {

crates/ninep/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ util_fs = ["dep:uzers"]
2121
[dependencies]
2222
bitflags = "2"
2323
jiff = "0.2"
24-
parking_lot = "0.12.5"
24+
parking_lot = "0.12"
2525
simple_coro = "0.1.5"
2626
tokio = { version = "1", features = ["macros", "net", "io-util", "rt", "sync"], optional = true }
2727
uzers = { version = "0.12", optional = true }

crates/ninep/src/fs/simple.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ use crate::{
66
fs::{FileType, Perm, QID_ROOT, Qid, Stat, WStat},
77
sansio::server::{E_CREATE_NON_DIR, E_ILLEGAL_CREATE_NAME, E_UNKNOWN_FILE},
88
};
9-
use std::{
10-
collections::BTreeMap,
11-
sync::{Arc, RwLock},
12-
};
9+
use parking_lot::RwLock;
10+
use std::{collections::BTreeMap, sync::Arc};
1311

1412
const E_ALREADY_EXISTS: &str = "file already exists";
1513

@@ -37,14 +35,14 @@ where
3735
where
3836
F: FnOnce(&Nodes<T>) -> U,
3937
{
40-
f(&self.nodes.read().unwrap())
38+
f(&self.nodes.read())
4139
}
4240

4341
fn with_nodes_mut<F, U>(&self, f: F) -> U
4442
where
4543
F: FnOnce(&mut Nodes<T>) -> U,
4644
{
47-
f(&mut self.nodes.write().unwrap())
45+
f(&mut self.nodes.write())
4846
}
4947

5048
/// Add a new node to the tree, returning its `qid`.

crates/ninep/src/sansio/server.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
DEFAULT_MSIZE, FileType, MAXWELEM, NineP, Qid, RawStat, Rdata, SharedBuf, Tdata, Tmessage,
77
},
88
};
9+
use parking_lot::RwLock;
910
use simple_coro::{Coro, Handle, ReadyCoro};
1011
use std::{
1112
cmp::min,
@@ -14,7 +15,7 @@ use std::{
1415
future::Future,
1516
ops::{Deref, DerefMut},
1617
path::{Path, PathBuf},
17-
sync::{Arc, RwLock},
18+
sync::Arc,
1819
};
1920

2021
/// Marker afid to denode that auth is not required for establishing connections
@@ -153,7 +154,7 @@ impl SessionType for Attached {}
153154

154155
impl Drop for Attached {
155156
fn drop(&mut self) {
156-
let mut guard = self.qids.write().unwrap();
157+
let mut guard = self.qids.write();
157158
for fm in self.fids.values() {
158159
if let Some(meta) = guard.get_mut(&fm.qid) {
159160
meta.opened_by.remove(&self.client_id);
@@ -219,7 +220,7 @@ where
219220
where
220221
F: FnOnce(&BTreeMap<u64, QidMeta>) -> U,
221222
{
222-
f(&self.qids.read().unwrap())
223+
f(&self.qids.read())
223224
}
224225

225226
/// Run a closure with mutable access to the shared server-level Qid map.
@@ -231,7 +232,7 @@ where
231232
where
232233
F: FnOnce(&mut BTreeMap<u64, QidMeta>) -> U,
233234
{
234-
f(&mut self.qids.write().unwrap())
235+
f(&mut self.qids.write())
235236
}
236237

237238
pub(crate) fn parent_qid(&self, qid: u64) -> Option<u64> {

crates/ninep/src/test_utils/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ use crate::{
1414
tokio::{AsyncNineP, server::AsyncServe9pFromSync},
1515
};
1616
use jiff::Timestamp;
17+
use parking_lot::Mutex;
1718
use std::{
1819
io, mem,
1920
os::unix::net::UnixStream,
20-
sync::{Arc, Mutex, mpsc},
21+
sync::{Arc, mpsc},
2122
thread::{sleep, spawn},
2223
time::Duration,
2324
};
@@ -257,14 +258,14 @@ pub(crate) struct RecordedCalls(Arc<Mutex<Vec<Call>>>);
257258

258259
impl RecordedCalls {
259260
fn push(&self, call: Call) {
260-
self.0.lock().unwrap().push(call);
261+
self.0.lock().push(call);
261262
}
262263

263264
/// Extract the [Call]s that have been recorded up until this point.
264265
///
265266
/// This method clears the internal log state of the associated [TestFs].
266267
pub(crate) fn take(&self) -> Vec<Call> {
267-
mem::take(&mut self.0.lock().unwrap())
268+
mem::take(&mut self.0.lock())
268269
}
269270
}
270271

reference-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ opt-level = 3
1212
[dependencies]
1313
ad-editor = { path = "../" }
1414
libflate = "2.1.0"
15+
parking_lot = "0.12.5"
1516
serde = { version = "1.0.219", features = ["derive"] }
1617
serde_json = "1.0.143"
1718

reference-tests/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ impl From<(usize, usize, String)> for TestPatch {
9797
mod tests {
9898
use super::*;
9999
use ad_editor::Config;
100+
use parking_lot::RwLock;
100101
use pretty_assertions::assert_eq;
101-
use std::sync::{Arc, RwLock};
102+
use std::sync::Arc;
102103

103104
fn run_reference_test(name: &str) {
104105
let path = format!("{}/data/{name}.json.gz", env!("CARGO_MANIFEST_DIR"),);

0 commit comments

Comments
 (0)