-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync: Add RwLock::{try_read, try_write}
Closes #2284
- Loading branch information
Dmytro Lysai
committed
May 20, 2020
1 parent
f480659
commit 6cfc0d2
Showing
4 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
cfg_not_loom! { | ||
mod atomic_waker; | ||
mod rwlock; | ||
mod semaphore_ll; | ||
mod semaphore_batch; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::sync::rwlock::*; | ||
|
||
#[test] | ||
fn serial_try_read_write() { | ||
let l = RwLock::new(42); | ||
|
||
{ | ||
let g = l.try_read().unwrap(); | ||
assert_eq!(*g, 42); | ||
|
||
assert!(l.try_write().is_err()); | ||
|
||
let g2 = l.try_read().unwrap(); | ||
assert_eq!(*g2, 42); | ||
} | ||
|
||
{ | ||
let mut g = l.try_write().unwrap(); | ||
assert_eq!(*g, 42); | ||
*g = 4242; | ||
|
||
assert!(l.try_read().is_err()); | ||
} | ||
|
||
assert_eq!(*l.try_read().unwrap(), 4242); | ||
} |