-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite set_logger
function to use std::sync::Once
on std
#605
Rewrite set_logger
function to use std::sync::Once
on std
#605
Conversation
I think, CI failed because of errors in rustc. Newer rustc doesn't complain about ordering. Edit: found a reason - rust-lang/rust#98383 |
I think we should replace the atomic with |
What to do about targets without atomic sized pointers? I think |
I'm not suggesting |
So what should I do? I suppose I should not up the minimal rustc? I think, you should merge this PR and switch to OnceCell later when you move to rustc 1.70. |
I can also try to detect rustc during using build script and cfg in OnceCell but I don't think that it is wise. |
If you want, you can try to replace Then once we update our MSRV to 1.70+ we can use However, I don't know the reason why the current approach was taken over using
We used to have that, let's not go back to that. |
I think, the main problem with |
set_logger
function to use std::sync::Once
on std
I split implementations for 3 cases: * When std is available, use standard locking primitive. * When std is not available but there is atomics with pointer size, use spinlock * If there is no atomic with pointer size, assume that there is no threads and use `Cell`. I think, this separation makes easier to understand what is happening in each case. Also: * Replaced `SeqCst` by weaker orderings because they are enough * Removed alias from `core` to `std` because it is confusing
Put it into draft until #608 is merged. |
I don't have a horse in this race, but FWIW there are a number of targets where this is not true. |
I'm not sure about these changes. As @thomcc mentions they could be incorrect for a number of targets we support. Furthermore the code doesn't get any simpler from it. |
@thomcc comment is about your current code, btw, because it is written cleverly to hide the fact it uses Cell by renaming Cell to AtomicUsize on targets without atomic pointers. The fact, that he noticed that now, proves that I made code simpler to read. If you're not going to accept this version, can we return PR to using just correct Orderings at least? |
Btw, @thomcc can you tell us which platforms you mean? |
@AngelicosPhosphoros the current code is carefully written to work on as many platforms as possible. We can't easily change it without possibly breaking support for some platforms. The work around in place are for platforms that don't support atomic operations or threads (think micro controllers). Rewriting the core of this library is not done on a whim, we need to be consider why the code was written as-is. |
I split implementations for 3 cases:
Cell
.I think, this separation makes easier to understand what is happening in each case.
Also:
SeqCst
by weaker orderings because they are enoughcore
tostd
because it is confusing