]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/windows/sync.rs
rollup merge of #19577: aidancully/master
[rust.git] / src / libstd / sys / windows / sync.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 libc::{BOOL, DWORD, c_void, LPVOID};
12 use libc::types::os::arch::extra::BOOLEAN;
13
14 pub type LPCRITICAL_SECTION = *mut c_void;
15 pub type LPCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
16 pub type LPSRWLOCK = *mut SRWLOCK;
17
18 #[cfg(target_arch = "x86")]
19 pub const CRITICAL_SECTION_SIZE: uint = 24;
20 #[cfg(target_arch = "x86_64")]
21 pub const CRITICAL_SECTION_SIZE: uint = 40;
22
23 #[repr(C)]
24 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
25 #[repr(C)]
26 pub struct SRWLOCK { pub ptr: LPVOID }
27
28 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
29     ptr: 0 as *mut _,
30 };
31 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: 0 as *mut _ };
32
33 extern "system" {
34     // critical sections
35     pub fn InitializeCriticalSectionAndSpinCount(
36                     lpCriticalSection: LPCRITICAL_SECTION,
37                     dwSpinCount: DWORD) -> BOOL;
38     pub fn DeleteCriticalSection(lpCriticalSection: LPCRITICAL_SECTION);
39     pub fn EnterCriticalSection(lpCriticalSection: LPCRITICAL_SECTION);
40     pub fn LeaveCriticalSection(lpCriticalSection: LPCRITICAL_SECTION);
41     pub fn TryEnterCriticalSection(lpCriticalSection: LPCRITICAL_SECTION) -> BOOL;
42
43     // condition variables
44     pub fn SleepConditionVariableCS(ConditionVariable: LPCONDITION_VARIABLE,
45                                     CriticalSection: LPCRITICAL_SECTION,
46                                     dwMilliseconds: DWORD) -> BOOL;
47     pub fn WakeConditionVariable(ConditionVariable: LPCONDITION_VARIABLE);
48     pub fn WakeAllConditionVariable(ConditionVariable: LPCONDITION_VARIABLE);
49
50     // slim rwlocks
51     pub fn AcquireSRWLockExclusive(SRWLock: LPSRWLOCK);
52     pub fn AcquireSRWLockShared(SRWLock: LPSRWLOCK);
53     pub fn ReleaseSRWLockExclusive(SRWLock: LPSRWLOCK);
54     pub fn ReleaseSRWLockShared(SRWLock: LPSRWLOCK);
55     pub fn TryAcquireSRWLockExclusive(SRWLock: LPSRWLOCK) -> BOOLEAN;
56     pub fn TryAcquireSRWLockShared(SRWLock: LPSRWLOCK) -> BOOLEAN;
57 }
58