avoid using the word 'initialized' to talk about that non-reentrant-capable state of the mutex
This commit is contained in:
@@ -15,6 +15,7 @@ use sys_common;
|
|||||||
use sys_common::mutex::Mutex;
|
use sys_common::mutex::Mutex;
|
||||||
|
|
||||||
pub struct Lazy<T> {
|
pub struct Lazy<T> {
|
||||||
|
// We never call `lock.init()`, so it is UB to attempt to acquire this mutex reentrantly!
|
||||||
lock: Mutex,
|
lock: Mutex,
|
||||||
ptr: Cell<*mut Arc<T>>,
|
ptr: Cell<*mut Arc<T>>,
|
||||||
init: fn() -> Arc<T>,
|
init: fn() -> Arc<T>,
|
||||||
@@ -29,8 +30,6 @@ impl<T: Send + Sync + 'static> Lazy<T> {
|
|||||||
/// Safety: `init` must not call `get` on the variable that is being
|
/// Safety: `init` must not call `get` on the variable that is being
|
||||||
/// initialized.
|
/// initialized.
|
||||||
pub const unsafe fn new(init: fn() -> Arc<T>) -> Lazy<T> {
|
pub const unsafe fn new(init: fn() -> Arc<T>) -> Lazy<T> {
|
||||||
// `lock` is never initialized fully, so it is UB to attempt to
|
|
||||||
// acquire this mutex reentrantly!
|
|
||||||
Lazy {
|
Lazy {
|
||||||
lock: Mutex::new(),
|
lock: Mutex::new(),
|
||||||
ptr: Cell::new(ptr::null_mut()),
|
ptr: Cell::new(ptr::null_mut()),
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ mod imp {
|
|||||||
|
|
||||||
static mut ARGC: isize = 0;
|
static mut ARGC: isize = 0;
|
||||||
static mut ARGV: *const *const u8 = ptr::null();
|
static mut ARGV: *const *const u8 = ptr::null();
|
||||||
// `ENV_LOCK` is never initialized fully, so it is UB to attempt to
|
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
|
||||||
// acquire this mutex reentrantly!
|
// acquire this mutex reentrantly!
|
||||||
static LOCK: Mutex = Mutex::new();
|
static LOCK: Mutex = Mutex::new();
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use sys::fd;
|
|||||||
use vec;
|
use vec;
|
||||||
|
|
||||||
const TMPBUF_SZ: usize = 128;
|
const TMPBUF_SZ: usize = 128;
|
||||||
// `ENV_LOCK` is never initialized fully, so it is UB to attempt to
|
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
|
||||||
// acquire this mutex reentrantly!
|
// acquire this mutex reentrantly!
|
||||||
static ENV_LOCK: Mutex = Mutex::new();
|
static ENV_LOCK: Mutex = Mutex::new();
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ type Queue = Vec<Box<dyn FnBox()>>;
|
|||||||
// on poisoning and this module needs to operate at a lower level than requiring
|
// on poisoning and this module needs to operate at a lower level than requiring
|
||||||
// the thread infrastructure to be in place (useful on the borders of
|
// the thread infrastructure to be in place (useful on the borders of
|
||||||
// initialization/destruction).
|
// initialization/destruction).
|
||||||
// `LOCK` is never initialized fully, so it is UB to attempt to
|
// We never call `LOCK.init()`, so it is UB to attempt to
|
||||||
// acquire this mutex reentrantly!
|
// acquire this mutex reentrantly!
|
||||||
static LOCK: Mutex = Mutex::new();
|
static LOCK: Mutex = Mutex::new();
|
||||||
static mut QUEUE: *mut Queue = ptr::null_mut();
|
static mut QUEUE: *mut Queue = ptr::null_mut();
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ impl Mutex {
|
|||||||
/// Prepare the mutex for use.
|
/// Prepare the mutex for use.
|
||||||
///
|
///
|
||||||
/// This should be called once the mutex is at a stable memory address.
|
/// This should be called once the mutex is at a stable memory address.
|
||||||
/// Behavior is undefined unless this is called before any other operation.
|
/// If called, this must be the very first thing that happens to the mutex.
|
||||||
|
/// Calling it in parallel with or after any operation (including another
|
||||||
|
/// `init()`) is undefined behavior.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn init(&mut self) { self.0.init() }
|
pub unsafe fn init(&mut self) { self.0.init() }
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ impl StaticKey {
|
|||||||
// Additionally a 0-index of a tls key hasn't been seen on windows, so
|
// Additionally a 0-index of a tls key hasn't been seen on windows, so
|
||||||
// we just simplify the whole branch.
|
// we just simplify the whole branch.
|
||||||
if imp::requires_synchronized_create() {
|
if imp::requires_synchronized_create() {
|
||||||
// `INIT_LOCK` is never initialized fully, so it is UB to attempt to
|
// We never call `INIT_LOCK.init()`, so it is UB to attempt to
|
||||||
// acquire this mutex reentrantly!
|
// acquire this mutex reentrantly!
|
||||||
static INIT_LOCK: Mutex = Mutex::new();
|
static INIT_LOCK: Mutex = Mutex::new();
|
||||||
let _guard = INIT_LOCK.lock();
|
let _guard = INIT_LOCK.lock();
|
||||||
|
|||||||
@@ -940,7 +940,7 @@ pub struct ThreadId(u64);
|
|||||||
impl ThreadId {
|
impl ThreadId {
|
||||||
// Generate a new unique thread ID.
|
// Generate a new unique thread ID.
|
||||||
fn new() -> ThreadId {
|
fn new() -> ThreadId {
|
||||||
// `GUARD` is never initialized fully, so it is UB to attempt to
|
// We never call `GUARD.init()`, so it is UB to attempt to
|
||||||
// acquire this mutex reentrantly!
|
// acquire this mutex reentrantly!
|
||||||
static GUARD: mutex::Mutex = mutex::Mutex::new();
|
static GUARD: mutex::Mutex = mutex::Mutex::new();
|
||||||
static mut COUNTER: u64 = 0;
|
static mut COUNTER: u64 = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user