Skip to content

Commit 490acb0

Browse files
committed
Remove Once from init
1 parent 4f7b287 commit 490acb0

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

std/src/rt.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ fn lang_start_internal(
2828
use crate::panic;
2929
use crate::sys_common;
3030

31-
sys_common::rt::init(argc, argv);
31+
// SAFETY: Only called once during runtime initialization.
32+
unsafe { sys_common::rt::init(argc, argv) };
33+
3234
let exit_code = panic::catch_unwind(main);
35+
3336
sys_common::rt::cleanup();
3437

3538
exit_code.unwrap_or(101) as isize

std/src/sys_common/rt.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
#![deny(unsafe_op_in_unsafe_fn)]
2+
13
use crate::sync::Once;
24
use crate::sys;
35
use crate::sys_common::thread_info;
46
use crate::thread::Thread;
57

68
// One-time runtime initialization.
79
// Runs before `main`.
10+
// SAFETY: must be called only once during runtime initialization.
811
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
912
#[cfg_attr(test, allow(dead_code))]
10-
pub fn init(argc: isize, argv: *const *const u8) {
11-
static INIT: Once = Once::new();
12-
INIT.call_once(|| unsafe {
13-
// SAFETY: Only called once during runtime initialization.
13+
pub unsafe fn init(argc: isize, argv: *const *const u8) {
14+
unsafe {
1415
sys::init(argc, argv);
1516

1617
let main_guard = sys::thread::guard::init();
@@ -20,7 +21,7 @@ pub fn init(argc: isize, argv: *const *const u8) {
2021
// info about the stack bounds.
2122
let thread = Thread::new(Some("main".to_owned()));
2223
thread_info::set(main_guard, thread);
23-
});
24+
}
2425
}
2526

2627
// One-time runtime cleanup.

0 commit comments

Comments
 (0)