Skip to content

Commit

Permalink
Remove old dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Dec 13, 2019
1 parent b593647 commit 44a388b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
1 change: 0 additions & 1 deletion bastion-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jemallocator = { version = "^0.3", optional = true, default-features = false }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "^0.3.8", features = ["basetsd"] }
#winapi = "^0.2.8"
kernel32-sys = "^0.2.2"

[dev-dependencies]
Expand Down
37 changes: 23 additions & 14 deletions bastion-executor/src/placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ mod windows {
use kernel32::{
GetCurrentProcess, GetCurrentThread, GetProcessAffinityMask, SetThreadAffinityMask,
};
use winapi::shared::basetsd::{DWORD_PTR, PDWORD_PTR};
use winapi::shared::basetsd::{DWORD32, DWORD64, PDWORD32, PDWORD64};

use super::CoreId;

Expand Down Expand Up @@ -214,31 +214,40 @@ mod windows {

// Set core affinity for current thread.
unsafe {
#[cfg(target_pointer_width = "32")]
SetThreadAffinityMask(GetCurrentThread(), mask as DWORD_PTR as u32);
#[cfg(target_pointer_width = "64")]
SetThreadAffinityMask(GetCurrentThread(), mask as DWORD_PTR as u64);
SetThreadAffinityMask(GetCurrentThread(), mask as DWORD64);
}
}

fn get_affinity_mask() -> Option<u64> {
let mut process_mask: usize = 0;
let mut system_mask: usize = 0;
#[cfg(target_pointer_width = "64")]
let mut process_mask: u64 = 0;
#[cfg(target_pointer_width = "32")]
let mut process_mask: u32 = 0;
#[cfg(target_pointer_width = "64")]
let mut system_mask: u64 = 0;
#[cfg(target_pointer_width = "32")]
let mut system_mask: u32 = 0;

let res = unsafe {
// Good luck with other architectures.
// Since Windows is already like a cartoon:
// Tinky winky, dipsy, laa laa, po.

#[cfg(target_pointer_width = "32")]
let mut pm = process_mask as u32;
#[cfg(target_pointer_width = "64")]
let mut pm = process_mask as u64;
#[cfg(target_pointer_width = "32")]
let mut sm = system_mask as u32;
let r = GetProcessAffinityMask(
GetCurrentProcess(),
&mut process_mask as PDWORD32,
&mut system_mask as PDWORD32,
);

#[cfg(target_pointer_width = "64")]
let mut sm = system_mask as u64;
let r = GetProcessAffinityMask(
GetCurrentProcess(),
&mut process_mask as PDWORD64,
&mut system_mask as PDWORD64,
);

GetProcessAffinityMask(GetCurrentProcess(), &mut pm, &mut sm)
r
};

// Successfully retrieved affinity mask
Expand Down

0 comments on commit 44a388b

Please sign in to comment.