std: use queue-based RwLock on Windows 7

This commit is contained in:
joboet 2024-04-11 19:37:12 +02:00
parent 8afee14202
commit dbda4f91aa
No known key found for this signature in database
GPG Key ID: 704E0149B0194B3C
2 changed files with 6 additions and 50 deletions

View File

@ -12,24 +12,20 @@ cfg_if::cfg_if! {
))] {
mod futex;
pub use futex::RwLock;
} else if #[cfg(target_family = "unix")] {
} else if #[cfg(any(
target_family = "unix",
all(target_os = "windows", target_vendor = "win7"),
all(target_vendor = "fortanix", target_env = "sgx"),
target_os = "xous",
))] {
mod queue;
pub use queue::RwLock;
} else if #[cfg(all(target_os = "windows", target_vendor = "win7"))] {
mod windows7;
pub use windows7::RwLock;
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
mod sgx;
pub use sgx::RwLock;
} else if #[cfg(target_os = "solid_asp3")] {
mod solid;
pub use solid::RwLock;
} else if #[cfg(target_os = "teeos")] {
mod teeos;
pub use teeos::RwLock;
} else if #[cfg(target_os = "xous")] {
mod xous;
pub use xous::RwLock;
} else {
mod no_threads;
pub use no_threads::RwLock;

View File

@ -1,40 +0,0 @@
use crate::cell::UnsafeCell;
use crate::sys::c;
pub struct RwLock {
inner: UnsafeCell<c::SRWLOCK>,
}
unsafe impl Send for RwLock {}
unsafe impl Sync for RwLock {}
impl RwLock {
#[inline]
pub const fn new() -> RwLock {
RwLock { inner: UnsafeCell::new(c::SRWLOCK_INIT) }
}
#[inline]
pub fn read(&self) {
unsafe { c::AcquireSRWLockShared(self.inner.get()) }
}
#[inline]
pub fn try_read(&self) -> bool {
unsafe { c::TryAcquireSRWLockShared(self.inner.get()) != 0 }
}
#[inline]
pub fn write(&self) {
unsafe { c::AcquireSRWLockExclusive(self.inner.get()) }
}
#[inline]
pub fn try_write(&self) -> bool {
unsafe { c::TryAcquireSRWLockExclusive(self.inner.get()) != 0 }
}
#[inline]
pub unsafe fn read_unlock(&self) {
c::ReleaseSRWLockShared(self.inner.get())
}
#[inline]
pub unsafe fn write_unlock(&self) {
c::ReleaseSRWLockExclusive(self.inner.get())
}
}