File tree 7 files changed +9
-8
lines changed
7 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use sys_common;
15
15
use sys_common:: mutex:: Mutex ;
16
16
17
17
pub struct Lazy < T > {
18
+ // We never call `lock.init()`, so it is UB to attempt to acquire this mutex reentrantly!
18
19
lock : Mutex ,
19
20
ptr : Cell < * mut Arc < T > > ,
20
21
init : fn ( ) -> Arc < T > ,
@@ -29,8 +30,6 @@ impl<T: Send + Sync + 'static> Lazy<T> {
29
30
/// Safety: `init` must not call `get` on the variable that is being
30
31
/// initialized.
31
32
pub const unsafe fn new ( init : fn ( ) -> Arc < T > ) -> Lazy < T > {
32
- // `lock` is never initialized fully, so it is UB to attempt to
33
- // acquire this mutex reentrantly!
34
33
Lazy {
35
34
lock : Mutex :: new ( ) ,
36
35
ptr : Cell :: new ( ptr:: null_mut ( ) ) ,
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ mod imp {
80
80
81
81
static mut ARGC : isize = 0 ;
82
82
static mut ARGV : * const * const u8 = ptr:: null ( ) ;
83
- // `ENV_LOCK` is never initialized fully , so it is UB to attempt to
83
+ // We never call `ENV_LOCK.init()` , so it is UB to attempt to
84
84
// acquire this mutex reentrantly!
85
85
static LOCK : Mutex = Mutex :: new ( ) ;
86
86
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ use sys::fd;
33
33
use vec;
34
34
35
35
const TMPBUF_SZ : usize = 128 ;
36
- // `ENV_LOCK` is never initialized fully , so it is UB to attempt to
36
+ // We never call `ENV_LOCK.init()` , so it is UB to attempt to
37
37
// acquire this mutex reentrantly!
38
38
static ENV_LOCK : Mutex = Mutex :: new ( ) ;
39
39
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ type Queue = Vec<Box<dyn FnBox()>>;
23
23
// on poisoning and this module needs to operate at a lower level than requiring
24
24
// the thread infrastructure to be in place (useful on the borders of
25
25
// initialization/destruction).
26
- // `LOCK` is never initialized fully , so it is UB to attempt to
26
+ // We never call `LOCK.init()` , so it is UB to attempt to
27
27
// acquire this mutex reentrantly!
28
28
static LOCK : Mutex = Mutex :: new ( ) ;
29
29
static mut QUEUE : * mut Queue = ptr:: null_mut ( ) ;
Original file line number Diff line number Diff line change @@ -32,7 +32,9 @@ impl Mutex {
32
32
/// Prepare the mutex for use.
33
33
///
34
34
/// This should be called once the mutex is at a stable memory address.
35
- /// Behavior is undefined unless this is called before any other operation.
35
+ /// If called, this must be the very first thing that happens to the mutex.
36
+ /// Calling it in parallel with or after any operation (including another
37
+ /// `init()`) is undefined behavior.
36
38
#[ inline]
37
39
pub unsafe fn init ( & mut self ) { self . 0 . init ( ) }
38
40
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ impl StaticKey {
161
161
// Additionally a 0-index of a tls key hasn't been seen on windows, so
162
162
// we just simplify the whole branch.
163
163
if imp:: requires_synchronized_create ( ) {
164
- // `INIT_LOCK` is never initialized fully , so it is UB to attempt to
164
+ // We never call `INIT_LOCK.init()` , so it is UB to attempt to
165
165
// acquire this mutex reentrantly!
166
166
static INIT_LOCK : Mutex = Mutex :: new ( ) ;
167
167
let _guard = INIT_LOCK . lock ( ) ;
Original file line number Diff line number Diff line change @@ -940,7 +940,7 @@ pub struct ThreadId(u64);
940
940
impl ThreadId {
941
941
// Generate a new unique thread ID.
942
942
fn new ( ) -> ThreadId {
943
- // `GUARD` is never initialized fully , so it is UB to attempt to
943
+ // We never call `GUARD.init()` , so it is UB to attempt to
944
944
// acquire this mutex reentrantly!
945
945
static GUARD : mutex:: Mutex = mutex:: Mutex :: new ( ) ;
946
946
static mut COUNTER : u64 = 0 ;
You can’t perform that action at this time.
0 commit comments