std: use queue-based RwLock
on Windows 7
This commit is contained in:
parent
8afee14202
commit
dbda4f91aa
@ -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;
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user