Skip to content

Commit 43cd6e5

Browse files
committed
uptime: add comment to explain thread local
1 parent 2fa7a32 commit 43cd6e5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/uucore/src/lib/features/uptime.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ impl UError for UptimeError {
3838
}
3939
}
4040

41+
// setup_localization() stores its state in thread local storage,
42+
// so every thread that might format uptime strings has to call it once.
43+
// Track that per thread so our helpers can lazily initialize
44+
// the locale only once per thread.
4145
thread_local! {
4246
static LOCALE_READY: Cell<bool> = const { Cell::new(false) };
4347
}
4448

49+
// Lazily initialize the uptime localization for the current thread, marking it
50+
// done even if a sibling thread already ran setup_localization() so we avoid
51+
// propagating the "already initialized" error and only log unexpected failures
52+
// in debug builds.
4553
fn ensure_uptime_locale() {
4654
LOCALE_READY.with(|ready| {
4755
if ready.get() {

0 commit comments

Comments
 (0)