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.
11 use libc::{BOOL, DWORD, c_void, LPVOID};
12 use libc::types::os::arch::extra::BOOLEAN;
14 pub type LPCRITICAL_SECTION = *mut c_void;
15 pub type LPCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
16 pub type LPSRWLOCK = *mut SRWLOCK;
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;
24 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
26 pub struct SRWLOCK { pub ptr: LPVOID }
28 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
31 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: 0 as *mut _ };
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;
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);
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;