From f93ccc1a95e462c575081fa603378615a4be3260 Mon Sep 17 00:00:00 2001 From: Mark Drobnak Date: Mon, 14 Mar 2022 21:13:58 -0700 Subject: [PATCH] Fix link errors by using inlining The release build (ex. for ctru-rs examples) was doing some extra optimizations and throwing away the submodules of this crate after the refactor split it into multiple files. For some reason if the init call is behind another function call, it is as if it doesn't exit. Luckily forcing inlining makes sure the module doesn't get thrown away. The `thread::attr` init call also needs to appear in the top level init, otherwise you still get link errors. --- src/lib.rs | 2 ++ src/thread.rs | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6d30dc5..1b0a943 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,11 +15,13 @@ mod thread_keys; /// The call doesn't need to execute, just exist. /// /// See https://github.com/rust-lang/rust/issues/47384 +#[inline(always)] pub fn init() { condvar::init(); misc::init(); mutex::init(); rwlock::init(); thread::init(); + thread::attr::init(); thread_keys::init(); } diff --git a/src/thread.rs b/src/thread.rs index c7f4d55..ff973b1 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -6,11 +6,9 @@ use std::collections::BTreeMap; use std::ptr; use std::sync::atomic::{AtomicUsize, Ordering}; -mod attr; +pub mod attr; -pub fn init() { - attr::init(); -} +pub fn init() {} /// The main thread's pthread ID const MAIN_THREAD_ID: libc::pthread_t = 0;