Skip to content

Commit

Permalink
Make Condvar::new and RWLock::new min const fn for cloudabi
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Aug 31, 2018
1 parent f3e1b96 commit b68bb63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/libstd/sys/cloudabi/condvar.rs
Expand Up @@ -28,11 +28,13 @@ pub struct Condvar {
unsafe impl Send for Condvar {}
unsafe impl Sync for Condvar {}

const NEW: Condvar = Condvar {
condvar: UnsafeCell::new(AtomicU32::new(abi::CONDVAR_HAS_NO_WAITERS.0)),
};

impl Condvar {
pub const fn new() -> Condvar {
Condvar {
condvar: UnsafeCell::new(AtomicU32::new(abi::CONDVAR_HAS_NO_WAITERS.0)),
}
NEW
}

pub unsafe fn init(&mut self) {}
Expand Down
8 changes: 5 additions & 3 deletions src/libstd/sys/cloudabi/rwlock.rs
Expand Up @@ -32,11 +32,13 @@ pub unsafe fn raw(r: &RWLock) -> *mut AtomicU32 {
unsafe impl Send for RWLock {}
unsafe impl Sync for RWLock {}

const NEW: RWLock = RWLock {
lock: UnsafeCell::new(AtomicU32::new(abi::LOCK_UNLOCKED.0)),
};

impl RWLock {
pub const fn new() -> RWLock {
RWLock {
lock: UnsafeCell::new(AtomicU32::new(abi::LOCK_UNLOCKED.0)),
}
NEW
}

pub unsafe fn try_read(&self) -> bool {
Expand Down

0 comments on commit b68bb63

Please sign in to comment.