mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 22:53:28 +00:00
Rollup merge of #44374 - jsheard:threadname, r=alexcrichton
Implement named threads on Windows (v2) https://msdn.microsoft.com/en-us/library/windows/desktop/mt774976(v=vs.85).aspx Windows 10 version 1607 finally added a sensible API for naming threads, so we can now implement named threads without having to use MSVC compiler extensions like before. VS2017s debugger and the WPA profiler already use this API where available, but other tools may need some time to catch up. ![thread](https://user-images.githubusercontent.com/3153547/30133438-c92a3cda-934b-11e7-9668-915d53e8d860.png)
This commit is contained in:
commit
3ef792a035
@ -32,6 +32,7 @@ pub type DWORD = c_ulong;
|
|||||||
pub type HANDLE = LPVOID;
|
pub type HANDLE = LPVOID;
|
||||||
pub type HINSTANCE = HANDLE;
|
pub type HINSTANCE = HANDLE;
|
||||||
pub type HMODULE = HINSTANCE;
|
pub type HMODULE = HINSTANCE;
|
||||||
|
pub type HRESULT = LONG;
|
||||||
pub type BOOL = c_int;
|
pub type BOOL = c_int;
|
||||||
pub type BYTE = u8;
|
pub type BYTE = u8;
|
||||||
pub type BOOLEAN = BYTE;
|
pub type BOOLEAN = BYTE;
|
||||||
@ -197,6 +198,8 @@ pub const ERROR_OPERATION_ABORTED: DWORD = 995;
|
|||||||
pub const ERROR_IO_PENDING: DWORD = 997;
|
pub const ERROR_IO_PENDING: DWORD = 997;
|
||||||
pub const ERROR_TIMEOUT: DWORD = 0x5B4;
|
pub const ERROR_TIMEOUT: DWORD = 0x5B4;
|
||||||
|
|
||||||
|
pub const E_NOTIMPL: HRESULT = 0x80004001u32 as HRESULT;
|
||||||
|
|
||||||
pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
|
pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
|
||||||
|
|
||||||
pub const FACILITY_NT_BIT: DWORD = 0x1000_0000;
|
pub const FACILITY_NT_BIT: DWORD = 0x1000_0000;
|
||||||
@ -1163,8 +1166,8 @@ extern "system" {
|
|||||||
timeout: *const timeval) -> c_int;
|
timeout: *const timeval) -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions that aren't available on Windows XP, but we still use them and just
|
// Functions that aren't available on every version of Windows that we support,
|
||||||
// provide some form of a fallback implementation.
|
// but we still use them and just provide some form of a fallback implementation.
|
||||||
compat_fn! {
|
compat_fn! {
|
||||||
kernel32:
|
kernel32:
|
||||||
|
|
||||||
@ -1182,6 +1185,10 @@ compat_fn! {
|
|||||||
pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
|
pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL {
|
||||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0
|
||||||
}
|
}
|
||||||
|
pub fn SetThreadDescription(hThread: HANDLE,
|
||||||
|
lpThreadDescription: LPCWSTR) -> HRESULT {
|
||||||
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL
|
||||||
|
}
|
||||||
pub fn SetFileInformationByHandle(_hFile: HANDLE,
|
pub fn SetFileInformationByHandle(_hFile: HANDLE,
|
||||||
_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
|
_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
|
||||||
_lpFileInformation: LPVOID,
|
_lpFileInformation: LPVOID,
|
||||||
|
@ -19,6 +19,8 @@ use sys::handle::Handle;
|
|||||||
use sys_common::thread::*;
|
use sys_common::thread::*;
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
|
|
||||||
|
use super::to_u16s;
|
||||||
|
|
||||||
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
|
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
|
||||||
|
|
||||||
pub struct Thread {
|
pub struct Thread {
|
||||||
@ -55,11 +57,12 @@ impl Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_name(_name: &CStr) {
|
pub fn set_name(name: &CStr) {
|
||||||
// Windows threads are nameless
|
if let Ok(utf8) = name.to_str() {
|
||||||
// The names in MSVC debugger are obtained using a "magic" exception,
|
if let Ok(utf16) = to_u16s(utf8) {
|
||||||
// which requires a use of MS C++ extensions.
|
unsafe { c::SetThreadDescription(c::GetCurrentThread(), utf16.as_ptr()); };
|
||||||
// See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn join(self) {
|
pub fn join(self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user