Skip to content

Commit b17491c

Browse files
committed
Auto merge of rust-lang#110211 - joboet:queue_lock, r=Amanieu
Replace pthread `RwLock` with custom implementation This is one of the last items in rust-lang#93740. I'm doing `RwLock` first because it is more self-contained and has less tradeoffs to make. The motivation is explained in the documentation, but in short: the pthread rwlock is slow and buggy and `std` can do much better. I considered implementing a parking lot, as was discussed in the tracking issue, but settled for the queue-based version because writing self-balancing binary trees is not fun in Rust... This is a rather complex change, so I have added quite a bit of documentation to help explain it. Please point out any part that could be explained better. ~~The read performance is really good, I'm getting 4x the throughput of the pthread version and about the same performance as usync/parking_lot on an Apple M1 Max in the usync benchmark suite, but the write performance still falls way behind what usync and parking_lot achieve. I tried using a separate queue lock like what usync uses, but that didn't help. I'll try to investigate further in the future, but I wanted to get some eyes on this first.~~ [Resolved](rust-lang#110211 (comment)) r? `@m-ou-se` CC `@kprotty`
2 parents aebf451 + 04282db commit b17491c

File tree

5 files changed

+571
-198
lines changed

5 files changed

+571
-198
lines changed

library/std/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,14 @@
339339
#![feature(portable_simd)]
340340
#![feature(prelude_2024)]
341341
#![feature(ptr_as_uninit)]
342+
#![feature(ptr_mask)]
342343
#![feature(slice_internals)]
343344
#![feature(slice_ptr_get)]
344345
#![feature(slice_range)]
345346
#![feature(std_internals)]
346347
#![feature(str_internals)]
347348
#![feature(strict_provenance)]
349+
#![feature(strict_provenance_atomic_ptr)]
348350
// tidy-alphabetical-end
349351
//
350352
// Library features (alloc):

library/std/src/sys/pal/unix/locks/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ cfg_if::cfg_if! {
2222
pub(crate) use futex_condvar::Condvar;
2323
} else {
2424
mod pthread_mutex;
25-
mod pthread_rwlock;
2625
mod pthread_condvar;
26+
mod queue_rwlock;
2727
pub(crate) use pthread_mutex::Mutex;
28-
pub(crate) use pthread_rwlock::RwLock;
28+
pub(crate) use queue_rwlock::RwLock;
2929
pub(crate) use pthread_condvar::Condvar;
3030
}
3131
}

library/std/src/sys/pal/unix/locks/pthread_rwlock.rs

-195
This file was deleted.

0 commit comments

Comments
 (0)