mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #98555 - mkroening:hermit-lock-init, r=m-ou-se
Hermit: Fix initializing lazy locks Closes https://github.com/hermitcore/rusty-hermit/issues/322. The initialization function of hermit's `Condvar` is not called since https://github.com/rust-lang/rust/pull/97647 and was erroneously removed in https://github.com/rust-lang/rust/pull/97879. r? ``@m-ou-se`` CC: ``@stlankes``
This commit is contained in:
commit
f181ae9946
@ -3,6 +3,7 @@ use crate::ptr;
|
||||
use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
||||
use crate::sys::hermit::abi;
|
||||
use crate::sys::locks::Mutex;
|
||||
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
|
||||
use crate::time::Duration;
|
||||
|
||||
// The implementation is inspired by Andrew D. Birrell's paper
|
||||
@ -14,14 +15,26 @@ pub struct Condvar {
|
||||
sem2: *const c_void,
|
||||
}
|
||||
|
||||
pub type MovableCondvar = Condvar;
|
||||
pub(crate) type MovableCondvar = LazyBox<Condvar>;
|
||||
|
||||
impl LazyInit for Condvar {
|
||||
fn init() -> Box<Self> {
|
||||
Box::new(Self::new())
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Condvar {}
|
||||
unsafe impl Sync for Condvar {}
|
||||
|
||||
impl Condvar {
|
||||
pub const fn new() -> Condvar {
|
||||
Condvar { counter: AtomicUsize::new(0), sem1: ptr::null(), sem2: ptr::null() }
|
||||
pub fn new() -> Self {
|
||||
let mut condvar =
|
||||
Self { counter: AtomicUsize::new(0), sem1: ptr::null(), sem2: ptr::null() };
|
||||
unsafe {
|
||||
let _ = abi::sem_init(&mut condvar.sem1, 0);
|
||||
let _ = abi::sem_init(&mut condvar.sem2, 0);
|
||||
}
|
||||
condvar
|
||||
}
|
||||
|
||||
pub unsafe fn notify_one(&self) {
|
||||
|
@ -175,9 +175,7 @@ impl Mutex {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init(&mut self) {
|
||||
self.inner = Spinlock::new(MutexInner::new());
|
||||
}
|
||||
pub unsafe fn init(&mut self) {}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn lock(&self) {
|
||||
|
@ -1,9 +1,10 @@
|
||||
use crate::cell::UnsafeCell;
|
||||
use crate::sys::locks::{Condvar, Mutex};
|
||||
use crate::sys::locks::{MovableCondvar, Mutex};
|
||||
use crate::sys_common::lazy_box::{LazyBox, LazyInit};
|
||||
|
||||
pub struct RwLock {
|
||||
lock: Mutex,
|
||||
cond: Condvar,
|
||||
cond: MovableCondvar,
|
||||
state: UnsafeCell<State>,
|
||||
}
|
||||
|
||||
@ -28,7 +29,11 @@ unsafe impl Sync for RwLock {}
|
||||
|
||||
impl RwLock {
|
||||
pub const fn new() -> RwLock {
|
||||
RwLock { lock: Mutex::new(), cond: Condvar::new(), state: UnsafeCell::new(State::Unlocked) }
|
||||
RwLock {
|
||||
lock: Mutex::new(),
|
||||
cond: MovableCondvar::new(),
|
||||
state: UnsafeCell::new(State::Unlocked),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user