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

implements avrt #324

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include = ["src/**/*", "Cargo.toml", "LICENSE.md"]

[dev-dependencies]
advapi32-sys = { version = "0", path = "lib/advapi32" }
avrt-sys = { version = "0", path = "lib/avrt" }
bcrypt-sys = { version = "0", path = "lib/bcrypt" }
comctl32-sys = { version = "0", path = "lib/comctl32" }
comdlg32-sys = { version = "0", path = "lib/comdlg32" }
Expand Down
Binary file added lib/avrt/i686/libavrt.a
Binary file not shown.
57 changes: 54 additions & 3 deletions lib/avrt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
// Copyright © 2015, Peter Atashian
// Licensed under the MIT License <LICENSE.md>
//! FFI bindings to avrt.
#![no_std]
#![experimental]
#![cfg(windows)]
extern crate winapi;
use winapi::*;

extern "system" {
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;
}
Binary file added lib/avrt/x86_64/libavrt.a
Binary file not shown.
17 changes: 17 additions & 0 deletions src/avrt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © 2016, Baptiste AUBRY
// Licensed under the MIT License <LICENSE.md>

ENUM_NEG!{enum AVRT_PRIORITY {
AVRT_PRIORITY_VERYLOW = -2,
AVRT_PRIORITY_LOW,
AVRT_PRIORITY_NORMAL,
AVRT_PRIORITY_HIGH,
AVRT_PRIORITY_CRITICAL,
}}

ENUM!{enum AVRT_NOTIFICATION {
Copy link
Owner

Choose a reason for hiding this comment

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

Strangely enough, AVRT_NOTIFICATION was actually removed in the Windows 10 SDK. Since I try to track the latest Windows 10 SDK with winapi, I'd rather this not be here, unless you can provide a compelling reason for why it should be kept.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad. My visual studio was not properly setup to use the latest sdk... Hence I removed AVRT_NOTIFICATION
The rest doesn't seem to have been modified

AVRT_PROCESS_SUSPEND = 0,
AVRT_PROCESS_RESUME,
}}

pub const THREAD_ORDER_GROUP_INFINITE_TIMEOUT: ::LONGLONG = -1;
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub use std::os::raw::{
pub use activation::*;
pub use audioclient::*;
pub use audiosessiontypes::*;
pub use avrt::*;
pub use basetsd::*;
pub use bcrypt::*;
pub use cfg::*;
Expand Down Expand Up @@ -192,6 +193,7 @@ pub use xinput::*;
pub mod activation;
pub mod audioclient;
pub mod audiosessiontypes;
pub mod avrt;
pub mod basetsd;
pub mod bcrypt;
pub mod cfg;
Expand Down
27 changes: 27 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,33 @@ macro_rules! ENUM {
ENUM!{@gen $name, $variant, $($rest)*}
};
}

macro_rules! ENUM_NEG {
{enum $name:ident { $($variant:ident = $value:expr,)+ }} => {
#[repr(C)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct $name(pub i32);
$(pub const $variant: $name = $name($value);)+
};
{enum $name:ident { $variant:ident = $value:expr, $($rest:tt)* }} => {
#[repr(C)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct $name(pub i32);
pub const $variant: $name = $name($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 = $name($value);
ENUM_NEG!{@gen $name, $variant, $($rest)*}
};
{@gen $name:ident, $base:ident, $variant:ident, $($rest:tt)*} => {
pub const $variant: $name = $name($base.0 + 1i32);
ENUM_NEG!{@gen $name, $variant, $($rest)*}
};
}

macro_rules! FLAGS {
{enum $name:ident { $($variant:ident = $value:expr,)+ }} => {
#[repr(C)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
Expand Down
27 changes: 27 additions & 0 deletions tests/avrt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright © 2016, Baptiste AUBRY
// Licensed under the MIT License <LICENSE.md>
#![cfg(windows)]
extern crate avrt;
extern crate winapi;

use avrt::*;

#[inline(never)] fn bb<T>(_: T) {}
#[test] #[cfg(target_env = "msvc")]
fn functions() {
bb(AvSetMmThreadCharacteristicsA);
bb(AvSetMmThreadCharacteristicsW);
bb(AvSetMmMaxThreadCharacteristicsA);
bb(AvSetMmMaxThreadCharacteristicsW);
bb(AvRevertMmThreadCharacteristics);
bb(AvRtCreateThreadOrderingGroup);
bb(AvRtCreateThreadOrderingGroupExA);
bb(AvRtCreateThreadOrderingGroupExW);
bb(AvRtJoinThreadOrderingGroup);
bb(AvRtWaitOnThreadOrderingGroup);
bb(AvRtLeaveThreadOrderingGroup);
bb(AvRtDeleteThreadOrderingGroup);
bb(AvQuerySystemResponsiveness);

assert_eq!(winapi::THREAD_ORDER_GROUP_INFINITE_TIMEOUT, -1);
}