rust/library
Yuki Okushi 1c4a5f8d1e
Rollup merge of #77147 - fusion-engineering-forks:static-mutex, r=dtolnay
Split sys_common::Mutex in StaticMutex and MovableMutex.

The (unsafe) `Mutex` from `sys_common` had a rather complicated interface. You were supposed to call `init()` manually, unless you could guarantee it was neither moved nor used reentrantly.

Calling `destroy()` was also optional, although it was unclear if 1) resources might be leaked or not, and 2) if `destroy()` should only be called when `init()` was called.

This allowed for a number of interesting (confusing?) different ways to use this `Mutex`, all captured in a single type.

In practice, this type was only ever used in two ways:

1. As a static variable. In this case, neither `init()` nor `destroy()` are called. The variable is never moved, and it is never used reentrantly. It is only ever locked using the `LockGuard`, never with `raw_lock`.

2. As a `Box`ed variable. In this case, both `init()` and `destroy()` are called, it will be moved and possibly used reentrantly.

No other combinations are used anywhere in `std`.

This change simplifies things by splitting this `Mutex` type into two types matching the two use cases: `StaticMutex` and `MovableMutex`.

The interface of both new types is now both safer and simpler. The first one does not call nor expose `init`/`destroy`, and the second one calls those automatically in its `new()` and `Drop` functions. Also, the locking functions of `MovableMutex` are no longer unsafe.

---

This will also make it easier to conditionally box mutexes later, by moving that decision into sys/sys_common. Some of the mutex implementations (at least those of Wasm and 'sys/unsupported') are safe to move, so wouldn't need a box. ~~(But that's blocked on  #76932 for now.)~~ (See #77380.)
2020-10-02 08:25:15 +09:00
..
alloc Auto merge of #77383 - pickfire:patch-6, r=Mark-Simulacrum 2020-10-01 05:35:48 +00:00
backtrace@4083a90168 std: Switch from libbacktrace to gimli 2020-07-28 16:34:01 -07:00
core Rollup merge of #77111 - fusion-engineering-forks:stabilize-slice-ptr-range, r=dtolnay 2020-10-02 08:25:13 +09:00
panic_abort Rollup merge of #76866 - est31:master, r=lcnr 2020-09-20 15:51:50 +02:00
panic_unwind library/{panic_,}unwind: Add definitions for sparc-unknow-linux-gnu 2020-09-28 00:39:57 +02:00
proc_macro Add a feature gate for basic function pointer use in const fn 2020-09-27 10:46:41 -07:00
profiler_builtins Fix warning whe building profiler_builtins crate 2020-09-04 15:10:29 +02:00
rtstartup
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Rollup merge of #77147 - fusion-engineering-forks:static-mutex, r=dtolnay 2020-10-02 08:25:15 +09:00
stdarch@b422b0180f fix redundant delarations of const_fn_transmute 2020-09-27 15:13:32 +08:00
term
test libary: Forward compiler-builtins "mem" feature 2020-09-27 20:31:06 -07:00
unwind library/{panic_,}unwind: Add definitions for sparc-unknow-linux-gnu 2020-09-28 00:39:57 +02:00