1 // Copyright 2014 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.
12 use libc::{self, DWORD};
14 use sys::mutex::{self, Mutex};
18 pub struct Condvar { inner: UnsafeCell<ffi::CONDITION_VARIABLE> }
20 pub const CONDVAR_INIT: Condvar = Condvar {
21 inner: UnsafeCell { value: ffi::CONDITION_VARIABLE_INIT }
26 pub unsafe fn new() -> Condvar { CONDVAR_INIT }
29 pub unsafe fn wait(&self, mutex: &Mutex) {
30 let r = ffi::SleepConditionVariableCS(self.inner.get(),
33 debug_assert!(r != 0);
36 pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
37 let r = ffi::SleepConditionVariableCS(self.inner.get(),
39 dur.num_milliseconds() as DWORD);
41 const ERROR_TIMEOUT: DWORD = 0x5B4;
42 debug_assert_eq!(os::errno() as uint, ERROR_TIMEOUT as uint);
50 pub unsafe fn notify_one(&self) {
51 ffi::WakeConditionVariable(self.inner.get())
55 pub unsafe fn notify_all(&self) {
56 ffi::WakeAllConditionVariable(self.inner.get())
59 pub unsafe fn destroy(&self) {