Skip to content

Commit

Permalink
rt: remove a conditional compilation clause (#5104)
Browse files Browse the repository at this point in the history
The `LocalSet` implementation includes a conditional compilation clause
that removes the `const` statement from the `thread_local` definition.
However, there already is an internal macro that does this:
`tokio_thread_local`.

This patch removes the conditional compilation in favor of using the
`tokio_thread_local` macro. This also fixes a conditional compilation
issue with an internal utility (`RcCell`).
  • Loading branch information
carllerche committed Oct 13, 2022
1 parent 964535e commit f809743
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
7 changes: 0 additions & 7 deletions tokio/src/task/local.rs
Expand Up @@ -272,13 +272,6 @@ pin_project! {
}
}

#[cfg(any(loom, tokio_no_const_thread_local))]
tokio_thread_local!(static CURRENT: LocalData = LocalData {
thread_id: Cell::new(None),
ctx: RcCell::new(),
});

#[cfg(not(any(loom, tokio_no_const_thread_local)))]
tokio_thread_local!(static CURRENT: LocalData = const { LocalData {
thread_id: Cell::new(None),
ctx: RcCell::new(),
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/util/rc_cell.rs
Expand Up @@ -9,15 +9,15 @@ pub(crate) struct RcCell<T> {
}

impl<T> RcCell<T> {
#[cfg(not(loom))]
#[cfg(not(all(loom, test)))]
pub(crate) const fn new() -> Self {
Self {
inner: UnsafeCell::new(None),
}
}

// The UnsafeCell in loom does not have a const `new` fn.
#[cfg(loom)]
#[cfg(all(loom, test))]
pub(crate) fn new() -> Self {
Self {
inner: UnsafeCell::new(None),
Expand Down

0 comments on commit f809743

Please sign in to comment.