]>
git.proxmox.com Git - rustc.git/blob - library/std/src/sys_common/condvar.rs
1 use crate::sys
::condvar
as imp
;
2 use crate::sys_common
::mutex
::MovableMutex
;
3 use crate::time
::Duration
;
5 /// An OS-based condition variable.
7 /// This structure is the lowest layer possible on top of the OS-provided
8 /// condition variables. It is consequently entirely unsafe to use. It is
9 /// recommended to use the safer types at the top level of this crate instead of
11 pub struct Condvar(imp
::Condvar
);
14 /// Creates a new condition variable for use.
16 /// Behavior is undefined if the condition variable is moved after it is
17 /// first used with any of the functions below.
18 pub const fn new() -> Condvar
{
19 Condvar(imp
::Condvar
::new())
22 /// Prepares the condition variable for use.
24 /// This should be called once the condition variable is at a stable memory
27 pub unsafe fn init(&mut self) {
31 /// Signals one waiter on this condition variable to wake up.
33 pub unsafe fn notify_one(&self) {
37 /// Awakens all current waiters on this condition variable.
39 pub unsafe fn notify_all(&self) {
43 /// Waits for a signal on the specified mutex.
45 /// Behavior is undefined if the mutex is not locked by the current thread.
46 /// Behavior is also undefined if more than one mutex is used concurrently
47 /// on this condition variable.
49 pub unsafe fn wait(&self, mutex
: &MovableMutex
) {
50 self.0.wait(mutex
.raw())
53 /// Waits for a signal on the specified mutex with a timeout duration
54 /// specified by `dur` (a relative time into the future).
56 /// Behavior is undefined if the mutex is not locked by the current thread.
57 /// Behavior is also undefined if more than one mutex is used concurrently
58 /// on this condition variable.
60 pub unsafe fn wait_timeout(&self, mutex
: &MovableMutex
, dur
: Duration
) -> bool
{
61 self.0.wait_timeout(mutex
.raw(), dur
)
64 /// Deallocates all resources associated with this condition variable.
66 /// Behavior is undefined if there are current or will be future users of
67 /// this condition variable.
69 pub unsafe fn destroy(&self) {