Skip to content

Commit

Permalink
Remove Once from init
Browse files Browse the repository at this point in the history
  • Loading branch information
CDirkx committed Apr 22, 2021
1 parent e1b1081 commit 7171fec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion library/std/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ fn lang_start_internal(
use crate::panic;
use crate::sys_common;

sys_common::rt::init(argc, argv);
// SAFETY: Only called once during runtime initialization.
unsafe { sys_common::rt::init(argc, argv) };

let exit_code = panic::catch_unwind(main);

sys_common::rt::cleanup();

exit_code.unwrap_or(101) as isize
Expand Down
11 changes: 6 additions & 5 deletions library/std/src/sys_common/rt.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#![deny(unsafe_op_in_unsafe_fn)]

use crate::sync::Once;
use crate::sys;
use crate::sys_common::thread_info;
use crate::thread::Thread;

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

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

// One-time runtime cleanup.
Expand Down

0 comments on commit 7171fec

Please sign in to comment.