Skip to content

Commit

Permalink
add simple downgrade implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
connortsui20 committed Nov 16, 2024
1 parent 48bcf09 commit 572aded
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions std/src/sys/sync/rwlock/no_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ impl RwLock {
pub unsafe fn write_unlock(&self) {
assert_eq!(self.mode.replace(0), -1);
}

#[inline]
pub unsafe fn downgrade(&self) {
assert_eq!(self.mode.replace(1), -1);
}
}
6 changes: 6 additions & 0 deletions std/src/sys/sync/rwlock/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ impl RwLock {
let rwl = self.raw();
expect_success_aborting(unsafe { abi::rwl_unl_rwl(rwl) }, &"rwl_unl_rwl");
}

#[inline]
pub unsafe fn downgrade(&self) {
// The SOLID platform does not support the `downgrade` operation for reader writer locks, so
// this function is simply a no-op as only 1 reader can read: the original writer.
}
}

impl Drop for RwLock {
Expand Down
6 changes: 6 additions & 0 deletions std/src/sys/sync/rwlock/teeos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ impl RwLock {
pub unsafe fn write_unlock(&self) {
unsafe { self.inner.unlock() };
}

#[inline]
pub unsafe fn downgrade(&self) {
// Since there is no difference between read-locked and write-locked on this platform, this
// function is simply a no-op as only 1 reader can read: the original writer.
}
}

0 comments on commit 572aded

Please sign in to comment.