rust/library/std/src
bors fa41639427 Auto merge of #77618 - fusion-engineering-forks:windows-parker, r=Amanieu
Add fast futex-based thread parker for Windows.

This adds a fast futex-based thread parker for Windows. It either uses WaitOnAddress+WakeByAddressSingle or NT Keyed Events (NtWaitForKeyedEvent+NtReleaseKeyedEvent), depending on which is available. Together, this makes this thread parker work for Windows XP and up. Before this change, park()/unpark() did not work on Windows XP: it needs condition variables, which only exist since Windows Vista.

---

Unfortunately, NT Keyed Events are an undocumented Windows API. However:
- This API is relatively simple with obvious behaviour, and there are several (unofficial) articles documenting the details. [1]
- parking_lot has been using this API for years (on Windows versions before Windows 8). [2] Many big projects extensively use parking_lot, such as servo and the Rust compiler itself.
- It is the underlying API used by Windows SRW locks and Windows critical sections. [3] [4]
- The source code of the implementations of Wine, ReactOs, and Windows XP are available and match the expected behaviour.
- The main risk with an undocumented API is that it might change in the future. But since we only use it for older versions of Windows, that's not a problem.
- Even if these functions do not block or wake as we expect (which is unlikely, see all previous points), this implementation would still be memory safe. The NT Keyed Events API is only used to sleep/block in the right place.

[1]\: http://www.locklessinc.com/articles/keyed_events/
[2]\: https://github.com/Amanieu/parking_lot/commit/43abbc964e
[3]\: https://docs.microsoft.com/en-us/archive/msdn-magazine/2012/november/windows-with-c-the-evolution-of-synchronization-in-windows-and-c
[4]\: Windows Internals, Part 1, ISBN 9780735671300

---

The choice of fallback API is inspired by parking_lot(_core), but the implementation of this thread parker is different. While parking_lot has no use for a fast path (park() directly returning if unpark() was already called), this implementation has a fast path that returns without even checking which waiting/waking API to use, as the same atomic variable with compatible states is used in all cases.
2020-12-14 16:41:14 +00:00
..
backtrace Add column number support to Backtrace 2020-11-15 13:09:56 +01:00
collections Rollup merge of #77996 - tkaitchuck:master, r=m-ou-se 2020-11-13 15:26:10 +01:00
env std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
error std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
f32 std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
f64 std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
ffi Bump bootstrap compiler version 2020-11-19 19:23:36 -05:00
fs std: Fix test got_symlink_permission on Windows 2020-11-16 21:09:26 +03:00
io Auto merge of #77801 - fusion-engineering-forks:pin-mutex, r=Mark-Simulacrum 2020-12-10 23:43:20 +00:00
lazy std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
memchr std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
net Move const ip in ui test to unit test 2020-11-26 23:15:32 +09:00
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os Take sys/vxworks/{fd,fs,io} from sys/unix instead. 2020-10-16 06:19:00 +02:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
prelude Fix incorrect link in prelude 2020-09-02 17:38:21 -04:00
process std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
sync Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
sys Auto merge of #77618 - fusion-engineering-forks:windows-parker, r=Amanieu 2020-12-14 16:41:14 +00:00
sys_common Auto merge of #77618 - fusion-engineering-forks:windows-parker, r=Amanieu 2020-12-14 16:41:14 +00:00
thread Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
time Duration::zero() -> Duration::ZERO 2020-10-21 20:44:03 -07:00
alloc.rs Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
ascii.rs Convert many files to intra-doc links 2020-09-02 17:37:40 -04:00
backtrace.rs Add column number support to Backtrace 2020-11-15 13:09:56 +01:00
env.rs Improve docs for std::env::args() 2020-09-04 14:00:09 -07:00
error.rs Rename LayoutErr to LayoutError outside of core 2020-10-08 00:40:10 -04:00
f32.rs Rollup merge of #77027 - termhn:mul_add_doc_change, r=m-ou-se 2020-12-10 21:32:59 -08:00
f64.rs Rollup merge of #77027 - termhn:mul_add_doc_change, r=m-ou-se 2020-12-10 21:32:59 -08:00
fs.rs Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
future.rs Fix stabilization marker for future_readiness_fns 2020-09-15 23:12:08 +02:00
keyword_docs.rs Rollup merge of #79398 - pickfire:keyword, r=Dylan-DPC 2020-12-13 11:05:30 +09:00
lazy.rs Add (internal-only) SyncOnceCell::get_or_init_pin. 2020-12-08 22:57:50 +01:00
lib.rs Rollup merge of #79809 - Eric-Arellano:split-once, r=matklad 2020-12-10 21:33:08 -08:00
macros.rs Use ? in core/std macros 2020-10-26 07:15:37 +09:00
memchr.rs std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
num.rs std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
panic.rs Add tracking issue number for panic_any. 2020-10-28 21:23:45 +01:00
panicking.rs Merge set_panic and set_print into set_output_capture. 2020-11-10 21:58:13 +01:00
path.rs Clean up intra-doc links in std::path 2020-10-27 20:54:30 -07:00
primitive_docs.rs doc: apply suggestions 2020-12-11 10:09:40 -05:00
process.rs Auto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrum 2020-11-23 19:01:19 +00:00
rt.rs Prevent __rust_begin_short_backtrace frames from being tail-call optimised away 2020-08-07 19:31:25 +01:00
time.rs Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00