Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement avrt with regard to #316 #348

Merged
merged 3 commits into from
Jan 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ headers = ["headers-shared", "headers-um", "headers-vc", "headers-winrt"]
"headers-um" = [
"um-audioclient",
"um-audiosessiontypes",
"um-avrt",
"um-cfgmgr32",
"um-cguid",
"um-combaseapi",
Expand Down Expand Up @@ -174,6 +175,7 @@ headers = ["headers-shared", "headers-um", "headers-vc", "headers-winrt"]
]
"um-audioclient" = ["shared-basetsd", "shared-guiddef", "shared-minwindef", "shared-mmreg", "shared-winerror", "shared-wtypesbase", "um-audiosessiontypes", "um-strmif", "um-unknwnbase", "um-winnt"]
"um-audiosessiontypes" = ["shared-minwindef"]
"um-avrt" = ["um-winnt", "avrt"]
"um-cfgmgr32" = ["shared-basetsd", "shared-guiddef", "shared-minwindef", "um-winnt"]
"um-cguid" = ["shared-guiddef"]
"um-combaseapi" = ["shared-basetsd", "shared-minwindef", "shared-wtypesbase", "um-objidlbase", "ole32"]
Expand Down Expand Up @@ -263,6 +265,7 @@ libraries = [
"ole32",
"wininet",
]
"avrt" = []
"kernel32" = []
"ole32" = []
"ncrypt" = []
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// except according to those terms.
use std::env::var;
const LIBS: &'static [&'static str] = &[
"avrt",
"kernel32",
"ncrypt",
"ole32",
Expand Down
Binary file added i686/lib/libavrt.a
Binary file not shown.
71 changes: 71 additions & 0 deletions lib/avrt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright © 2016 winapi-rs developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// All files in the project carrying such notice may not be copied, modified, or distributed
// except according to those terms.

#![cfg(windows)]
extern crate winapi;
use winapi::*;

extern "system" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions really should be defined in src/um/avrt.rs.

pub fn AvSetMmThreadCharacteristicsA(TaskName: winapi::LPCSTR,
TaskIndex: winapi::LPDWORD)
-> winapi::HANDLE;

pub fn AvSetMmThreadCharacteristicsW(TaskName: winapi::LPCSTR,
TaskIndex: winapi::LPDWORD)
-> winapi::HANDLE;

pub fn AvSetMmMaxThreadCharacteristicsA(FirstTask: winapi::LPCSTR,
SecondTask: winapi::LPCSTR,
TaskIndex: winapi::LPDWORD)
-> winapi::HANDLE;

pub fn AvSetMmMaxThreadCharacteristicsW(FirstTask: winapi::LPCWSTR,
SecondTask: winapi::LPCWSTR,
TaskIndex: winapi::LPDWORD)
-> winapi::HANDLE;

pub fn AvRevertMmThreadCharacteristics(avrt_handle: winapi::HANDLE) -> winapi::BOOL;

pub fn AvSetMmThreadPriority(AvrtHandle: winapi::HANDLE,
Priority: winapi::AVRT_PRIORITY)
-> winapi::BOOL;

pub fn AvRtCreateThreadOrderingGroup(Context: winapi::PHANDLE,
Period: winapi::PLARGE_INTEGER,
ThreadOrderingGuid: *mut winapi::GUID,
Timeout: winapi::PLARGE_INTEGER)
-> winapi::BOOL;

pub fn AvRtCreateThreadOrderingGroupExA(Context: winapi::PHANDLE,
Period: winapi::PLARGE_INTEGER,
ThreadOrderingGuid: *mut winapi::GUID,
Timeout: winapi::PLARGE_INTEGER,
TaskName: winapi::LPCSTR)
-> winapi::BOOL;

pub fn AvRtCreateThreadOrderingGroupExW(Context: winapi::PHANDLE,
Period: winapi::PLARGE_INTEGER,
ThreadOrderingGuid: *mut winapi::GUID,
Timeout: winapi::PLARGE_INTEGER,
TaskName: winapi::LPCWSTR)
-> winapi::BOOL;

pub fn AvRtJoinThreadOrderingGroup(Context: winapi::PHANDLE,
ThreadOrderingGuid: *mut winapi::GUID,
Before: winapi::BOOL)
-> winapi::BOOL;

pub fn AvRtWaitOnThreadOrderingGroup(Context: winapi::HANDLE) -> winapi::BOOL;

pub fn AvRtLeaveThreadOrderingGroup(Context: winapi::HANDLE) -> winapi::BOOL;

pub fn AvRtDeleteThreadOrderingGroup(Context: winapi::HANDLE) -> winapi::BOOL;

pub fn AvQuerySystemResponsiveness(AvrtHandle: winapi::HANDLE,
SystemResponsivenessValue: winapi::PULONG)
-> winapi::BOOL;
}
23 changes: 23 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,29 @@ macro_rules! ENUM {
ENUM!{@gen $name $variant, $($rest)*}
};
}
macro_rules! ENUM_NEG {
{enum $name:ident { $($variant:ident = $value:expr,)+ }} => {
pub type $name = i32;
$(pub const $variant: i32 = $value;)+
};
{enum $name:ident { $variant:ident = $value:expr, $($rest:tt)* }} => {
pub type $name = i32;
pub const $variant: i32 = $value;
ENUM_NEG!{@gen $name $variant, $($rest)*}
};
{enum $name:ident { $variant:ident, $($rest:tt)* }} => {
ENUM_NEG!{enum $name { $variant = 0, $($rest)* }}
};
{@gen $name:ident $base:ident,} => {};
{@gen $name:ident $base:ident, $variant:ident = $value:expr, $($rest:tt)*} => {
pub const $variant: $name = $value;
ENUM_NEG!{@gen $name $variant, $($rest)*}
};
{@gen $name:ident $base:ident, $variant:ident, $($rest:tt)*} => {
pub const $variant: $name = $base + 1i32;
ENUM_NEG!{@gen $name $variant, $($rest)*}
};
}
macro_rules! STRUCT {
{$(#[$attrs:meta])* struct $name:ident { $($field:ident: $ftype:ty,)+ }} => {
#[repr(C)] $(#[$attrs])*
Expand Down
18 changes: 18 additions & 0 deletions src/um/avrt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright © 2016 winapi-rs developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// All files in the project carrying such notice may not be copied, modified, or distributed
// except according to those terms.

use um::winnt::LONGLONG;

ENUM_NEG!{enum AVRT_PRIORITY {
AVRT_PRIORITY_VERYLOW = -2,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this be written as -2i32 as u32 and just using ENUM! instead of creating a new macro.

AVRT_PRIORITY_LOW,
AVRT_PRIORITY_NORMAL,
AVRT_PRIORITY_HIGH,
AVRT_PRIORITY_CRITICAL,
}}

pub const THREAD_ORDER_GROUP_INFINITE_TIMEOUT: LONGLONG = -1;
1 change: 1 addition & 0 deletions src/um/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod gl;

#[cfg(feature = "um-audioclient")] pub mod audioclient;
#[cfg(feature = "um-audiosessiontypes")] pub mod audiosessiontypes;
#[cfg(feature = "um-avrt")] pub mod avrt;
#[cfg(feature = "um-cfgmgr32")] pub mod cfgmgr32;
#[cfg(feature = "um-cguid")] pub mod cguid;
#[cfg(feature = "um-combaseapi")] pub mod combaseapi;
Expand Down
Binary file added x86_64/lib/libavrt.a
Binary file not shown.