1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 locked: UnsafeCell<bool>,
17 unsafe impl Send for Mutex {}
18 unsafe impl Sync for Mutex {} // FIXME
21 pub const fn new() -> Mutex {
22 Mutex { locked: UnsafeCell::new(false) }
26 pub unsafe fn init(&mut self) {
30 pub unsafe fn lock(&self) {
31 let locked = self.locked.get();
32 assert!(!*locked, "cannot recursively acquire mutex");
37 pub unsafe fn unlock(&self) {
38 *self.locked.get() = false;
42 pub unsafe fn try_lock(&self) -> bool {
43 let locked = self.locked.get();
53 pub unsafe fn destroy(&self) {
58 pub struct ReentrantMutex {
62 pub unsafe fn uninitialized() -> ReentrantMutex {
66 pub unsafe fn init(&mut self) {}
68 pub unsafe fn lock(&self) {}
71 pub unsafe fn try_lock(&self) -> bool {
75 pub unsafe fn unlock(&self) {}
77 pub unsafe fn destroy(&self) {}