Skip to content

Commit 4b0caec

Browse files
committed
Panic/return false on overflow in no_threads read/try_read impl
1 parent fb27476 commit 4b0caec

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

library/std/src/sys/sync/rwlock/no_threads.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ impl RwLock {
1717
#[inline]
1818
pub fn read(&self) {
1919
let m = self.mode.get();
20+
21+
// Check for overflow.
22+
assert!(m == isize::MAX, "too many active read locks on RwLock");
23+
2024
if m >= 0 {
2125
self.mode.set(m + 1);
2226
} else {
@@ -28,6 +32,9 @@ impl RwLock {
2832
pub fn try_read(&self) -> bool {
2933
let m = self.mode.get();
3034
if m >= 0 {
35+
if m == isize::MAX {
36+
return false;
37+
}
3138
self.mode.set(m + 1);
3239
true
3340
} else {

0 commit comments

Comments
 (0)