-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
std: Add a new top-level thread_local module #19094
Conversation
cc @aturon, @nikomatsakis, you may be interested in the API decisions here (everything panics) |
5b8c4c3
to
0ca71ca
Compare
I find "tls" to be a little ambiguous as a name, since it's already much in use for transport layer security. |
/* Common traits */ | ||
|
||
pub mod error; | ||
pub mod num; | ||
|
||
/* Runtime and platform support */ | ||
|
||
pub mod tls; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You ordered this alphabetically, except for tls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly this is due to how macros work, some of the modules below need the tls macro which requires it to be defined first.
50e714b
to
300f350
Compare
I'd also vote against utilizing the acronym |
@@ -213,7 +215,9 @@ pub const WARN: u32 = 2; | |||
/// Error log level | |||
pub const ERROR: u32 = 1; | |||
|
|||
local_data_key!(local_logger: Box<Logger + Send>) | |||
tls!(static LOCAL_LOGGER: RefCell<Option<Box<Logger + Send>>> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth providing a newtype abstraction around RefCell<Option<T>>
with a flattenend API; seems to come up from time to time.
OK, I've read over the entire implementation, pretty carefully. Great work! I'm happy with the panic semantics here. I agree with what others have mentioned about The module organization here strongly implies that the owned variant is the primary/default one, which is probably true, but we may want to revisit that before final stabilization. Other than the |
1fb6f9e
to
56a9f32
Compare
I've renamed every mention of "tls" to "thread_local" |
56a9f32
to
a29a998
Compare
a29a998
to
4395101
Compare
Is there a way forward for the |
This commit removes the `std::local_data` module in favor of a new `std::thread_local` module providing thread local storage. The module provides two variants of TLS: one which owns its contents and one which is based on scoped references. Each implementation has pros and cons listed in the documentation. Both flavors have accessors through a function called `with` which yield a reference to a closure provided. Both flavors also panic if a reference cannot be yielded and provide a function to test whether an access would panic or not. This is an implementation of [RFC 461][rfc] and full details can be found in that RFC. This is a breaking change due to the removal of the `std::local_data` module. All users can migrate to the new tls system like so: thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None))) The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as an implementation detail which must now be explicitly stated by users. [rfc]: rust-lang/rfcs#461 [breaking-change]
4395101
to
647d38d
Compare
@seanmonstar probably not, but that's more of a problem for liblog than the inherent design of this module itself. The purpose of this module is to expose the system primitives available with a safe interface. |
This commit removes the `std::local_data` module in favor of a new `std::thread_local` module providing thread local storage. The module provides two variants of TLS: one which owns its contents and one which is based on scoped references. Each implementation has pros and cons listed in the documentation. Both flavors have accessors through a function called `with` which yield a reference to a closure provided. Both flavors also panic if a reference cannot be yielded and provide a function to test whether an access would panic or not. This is an implementation of [RFC 461][rfc] and full details can be found in that RFC. This is a breaking change due to the removal of the `std::local_data` module. All users can migrate to the new tls system like so: thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None))) The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as an implementation detail which must now be explicitly stated by users. [rfc]: rust-lang/rfcs#461 [breaking-change]
647d38d
to
886b258
Compare
886b258
to
6d486d4
Compare
This commit removes the `std::local_data` module in favor of a new `std::thread_local` module providing thread local storage. The module provides two variants of TLS: one which owns its contents and one which is based on scoped references. Each implementation has pros and cons listed in the documentation. Both flavors have accessors through a function called `with` which yield a reference to a closure provided. Both flavors also panic if a reference cannot be yielded and provide a function to test whether an access would panic or not. This is an implementation of [RFC 461][rfc] and full details can be found in that RFC. This is a breaking change due to the removal of the `std::local_data` module. All users can migrate to the new thread local system like so: thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None))) The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as an implementation detail which must now be explicitly stated by users. [rfc]: rust-lang/rfcs#461 [breaking-change]
6d486d4
to
a9c1152
Compare
This commit removes the `std::local_data` module in favor of a new `std::thread_local` module providing thread local storage. The module provides two variants of TLS: one which owns its contents and one which is based on scoped references. Each implementation has pros and cons listed in the documentation. Both flavors have accessors through a function called `with` which yield a reference to a closure provided. Both flavors also panic if a reference cannot be yielded and provide a function to test whether an access would panic or not. This is an implementation of [RFC 461][rfc] and full details can be found in that RFC. This is a breaking change due to the removal of the `std::local_data` module. All users can migrate to the new tls system like so: thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None))) The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as an implementation detail which must now be explicitly stated by users. [rfc]: rust-lang/rfcs#461 [breaking-change]
This commit removes the
std::local_data
module in favor of a newstd::thread_local
module providing thread local storage. The module provides two variants of TLS:
one which owns its contents and one which is based on scoped references. Each
implementation has pros and cons listed in the documentation.
Both flavors have accessors through a function called
with
which yield areference to a closure provided. Both flavors also panic if a reference cannot
be yielded and provide a function to test whether an access would panic or not.
This is an implementation of RFC 461 and full details can be found in
that RFC.
This is a breaking change due to the removal of the
std::local_data
module.All users can migrate to the new tls system like so:
The old
local_data
module inherently contained theRc<RefCell<Option<T>>>
asan implementation detail which must now be explicitly stated by users.
[breaking-change]