]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/windows/condvar.rs
doc: remove incomplete sentence
[rust.git] / src / libstd / sys / windows / condvar.rs
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.
4 //
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.
10
11 use cell::UnsafeCell;
12 use libc::{mod, DWORD};
13 use os;
14 use sys::mutex::{mod, Mutex};
15 use sys::sync as ffi;
16 use time::Duration;
17
18 pub struct Condvar { inner: UnsafeCell<ffi::CONDITION_VARIABLE> }
19
20 pub const CONDVAR_INIT: Condvar = Condvar {
21     inner: UnsafeCell { value: ffi::CONDITION_VARIABLE_INIT }
22 };
23
24 impl Condvar {
25     #[inline]
26     pub unsafe fn new() -> Condvar { CONDVAR_INIT }
27
28     #[inline]
29     pub unsafe fn wait(&self, mutex: &Mutex) {
30         let r = ffi::SleepConditionVariableCS(self.inner.get(),
31                                               mutex::raw(mutex),
32                                               libc::INFINITE);
33         debug_assert!(r != 0);
34     }
35
36     pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
37         let r = ffi::SleepConditionVariableCS(self.inner.get(),
38                                               mutex::raw(mutex),
39                                               dur.num_milliseconds() as DWORD);
40         if r == 0 {
41             const ERROR_TIMEOUT: DWORD = 0x5B4;
42             debug_assert_eq!(os::errno() as uint, ERROR_TIMEOUT as uint);
43             false
44         } else {
45             true
46         }
47     }
48
49     #[inline]
50     pub unsafe fn notify_one(&self) {
51         ffi::WakeConditionVariable(self.inner.get())
52     }
53
54     #[inline]
55     pub unsafe fn notify_all(&self) {
56         ffi::WakeAllConditionVariable(self.inner.get())
57     }
58
59     pub unsafe fn destroy(&self) {
60         // ...
61     }
62 }