]> git.proxmox.com Git - rustc.git/blob - src/libstd/sys/windows/sync.rs
5410259540eaccbf5338c460a0c0c0add8a2a7c1
[rustc.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, LPVOID, LONG, HANDLE, c_ulong};
12 use libc::types::os::arch::extra::BOOLEAN;
13
14 pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE;
15 pub type PSRWLOCK = *mut SRWLOCK;
16 pub type ULONG = c_ulong;
17 pub type ULONG_PTR = c_ulong;
18
19 #[repr(C)]
20 pub struct CONDITION_VARIABLE { pub ptr: LPVOID }
21 #[repr(C)]
22 pub struct SRWLOCK { pub ptr: LPVOID }
23 #[repr(C)]
24 pub struct CRITICAL_SECTION {
25 CriticalSectionDebug: LPVOID,
26 LockCount: LONG,
27 RecursionCount: LONG,
28 OwningThread: HANDLE,
29 LockSemaphore: HANDLE,
30 SpinCount: ULONG_PTR
31 }
32
33 pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE {
34 ptr: 0 as *mut _,
35 };
36 pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { ptr: 0 as *mut _ };
37
38 extern "system" {
39 // condition variables
40 pub fn SleepConditionVariableSRW(ConditionVariable: PCONDITION_VARIABLE,
41 SRWLock: PSRWLOCK,
42 dwMilliseconds: DWORD,
43 Flags: ULONG) -> BOOL;
44 pub fn WakeConditionVariable(ConditionVariable: PCONDITION_VARIABLE);
45 pub fn WakeAllConditionVariable(ConditionVariable: PCONDITION_VARIABLE);
46
47 // slim rwlocks
48 pub fn AcquireSRWLockExclusive(SRWLock: PSRWLOCK);
49 pub fn AcquireSRWLockShared(SRWLock: PSRWLOCK);
50 pub fn ReleaseSRWLockExclusive(SRWLock: PSRWLOCK);
51 pub fn ReleaseSRWLockShared(SRWLock: PSRWLOCK);
52 pub fn TryAcquireSRWLockExclusive(SRWLock: PSRWLOCK) -> BOOLEAN;
53 pub fn TryAcquireSRWLockShared(SRWLock: PSRWLOCK) -> BOOLEAN;
54
55 pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
56 pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
57 pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
58 pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
59 pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
60 }