Skip to content

Commit 507b672

Browse files
committed
loosen orderings for logger initialization
1 parent c879b01 commit 507b672

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/lib.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@
341341
#![warn(missing_docs)]
342342
#![deny(missing_debug_implementations, unconditional_recursion)]
343343
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
344-
// When compiled for the rustc compiler itself we want to make sure that this is
345-
// an unstable crate
346-
#![cfg_attr(rustbuild, feature(staged_api, rustc_private))]
347-
#![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]
348344

349345
#[cfg(any(
350346
all(feature = "max_level_off", feature = "max_level_error"),
@@ -1405,24 +1401,21 @@ fn set_logger_inner<F>(make_logger: F) -> Result<(), SetLoggerError>
14051401
where
14061402
F: FnOnce() -> &'static dyn Log,
14071403
{
1408-
let old_state = match STATE.compare_exchange(
1404+
match STATE.compare_exchange(
14091405
UNINITIALIZED,
14101406
INITIALIZING,
1411-
Ordering::SeqCst,
1412-
Ordering::SeqCst,
1407+
Ordering::Acquire,
1408+
Ordering::Relaxed,
14131409
) {
1414-
Ok(s) | Err(s) => s,
1415-
};
1416-
match old_state {
1417-
UNINITIALIZED => {
1410+
Ok(UNINITIALIZED) => {
14181411
unsafe {
14191412
LOGGER = make_logger();
14201413
}
1421-
STATE.store(INITIALIZED, Ordering::SeqCst);
1414+
STATE.store(INITIALIZED, Ordering::Release);
14221415
Ok(())
14231416
}
1424-
INITIALIZING => {
1425-
while STATE.load(Ordering::SeqCst) == INITIALIZING {
1417+
Err(INITIALIZING) => {
1418+
while STATE.load(Ordering::Relaxed) == INITIALIZING {
14261419
std::hint::spin_loop();
14271420
}
14281421
Err(SetLoggerError(()))
@@ -1451,10 +1444,10 @@ where
14511444
///
14521445
/// [`set_logger`]: fn.set_logger.html
14531446
pub unsafe fn set_logger_racy(logger: &'static dyn Log) -> Result<(), SetLoggerError> {
1454-
match STATE.load(Ordering::SeqCst) {
1447+
match STATE.load(Ordering::Acquire) {
14551448
UNINITIALIZED => {
14561449
LOGGER = logger;
1457-
STATE.store(INITIALIZED, Ordering::SeqCst);
1450+
STATE.store(INITIALIZED, Ordering::Release);
14581451
Ok(())
14591452
}
14601453
INITIALIZING => {

tests/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ edition = "2021"
55
publish = false
66
build = "src/build.rs"
77

8+
[lints.rust]
9+
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(lib_build)'] }
10+
811
[features]
912
std = ["log/std"]
1013
kv = ["log/kv"]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy