rust/src/libstd/sys/windows
Alex Crichton cb57484dca std: Avoid usage of Once in Instant
This commit removes usage of `Once` from the internal implementation of
time utilities on OSX and Windows. It turns out that we accidentally hit
a deadlock today (#59020) via events that look like:

* A thread invokes `park_timeout`
* Internally, only on OSX, `park_timeout` calls `Instant::elapsed`
* Inside of `Instant::elapsed` on OSX we enter a `Once` to initialize
  global timer data
* Inside of `Once`, it attempts to `park`

This means on the same stack frame, when there's contention, we're
calling `park` from inside `park_timeout`, causing a deadlock!

The solution implemented in this commit was to remove usage of `Once`
and instead just do a small dance with atomics. There's no real need we
need to guarantee that the global information is only learned once, only
that it's only *stored* once. This implementation may have multiple
threads invoke `mach_timebase_info`, but only one will store the global
information which will amortize the cost for all other threads.

A similar fix has been applied to windows to be uniform across our
implementations, but looking at the code on Windows no deadlock was
possible. This is purely just a consistency update for Windows and in
theory a slightly leaner implementation.

Closes #59020
2019-04-04 07:19:14 -07:00
..
backtrace libstd => 2018 2019-02-28 04:06:15 +09:00
ext libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
alloc.rs libstd => 2018 2019-02-28 04:06:15 +09:00
args.rs libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
c.rs libstd => 2018 2019-02-28 04:06:15 +09:00
cmath.rs Remove licenses 2018-12-25 21:08:33 -07:00
compat.rs libstd => 2018 2019-02-28 04:06:15 +09:00
condvar.rs libstd => 2018 2019-02-28 04:06:15 +09:00
dynamic_lib.rs libstd => 2018 2019-02-28 04:06:15 +09:00
env.rs Remove licenses 2018-12-25 21:08:33 -07:00
fast_thread_local.rs libstd => 2018 2019-02-28 04:06:15 +09:00
fs.rs libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
handle.rs libstd => 2018 2019-02-28 04:06:15 +09:00
io.rs Fix rebase fail 2019-02-28 04:06:17 +09:00
memchr.rs Cosmetic improvements 2019-01-13 19:47:02 +00:00
mod.rs libstd => 2018 2019-02-28 04:06:15 +09:00
mutex.rs fix some uses I missed 2019-03-26 09:23:19 +01:00
net.rs libstd => 2018 2019-02-28 04:06:15 +09:00
os.rs libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
os_str.rs libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
path.rs libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
pipe.rs Improvements to comments in libstd, libcore, liballoc. 2019-03-11 02:25:44 +00:00
process.rs libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
rand.rs libstd => 2018 2019-02-28 04:06:15 +09:00
rwlock.rs libstd => 2018 2019-02-28 04:06:15 +09:00
stack_overflow.rs libstd => 2018 2019-02-28 04:06:15 +09:00
stdio.rs Fix rebase fail 2019-02-28 04:06:17 +09:00
thread.rs libstd => 2018 2019-02-28 04:06:15 +09:00
thread_local.rs libstd => 2018 2019-02-28 04:06:15 +09:00
time.rs std: Avoid usage of Once in Instant 2019-04-04 07:19:14 -07:00