Skip to content
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

sync: document that const_new() is not instrumented #6002

Merged
merged 1 commit into from Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions tokio/src/sync/mutex.rs
Expand Up @@ -371,13 +371,21 @@ impl<T: ?Sized> Mutex<T> {

/// Creates a new lock in an unlocked state ready for use.
///
/// When using the `tracing` [unstable feature], a `Mutex` created with
/// `const_new` will not be instrumented. As such, it will not be visible
/// in [`tokio-console`]. Instead, [`Mutex::new`] should be used to create
/// an instrumented object if that is needed.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// static LOCK: Mutex<i32> = Mutex::const_new(5);
/// ```
///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new(t: T) -> Self
where
Expand Down
8 changes: 8 additions & 0 deletions tokio/src/sync/notify.rs
Expand Up @@ -436,13 +436,21 @@ impl Notify {

/// Create a new `Notify`, initialized without a permit.
///
/// When using the `tracing` [unstable feature], a `Notify` created with
/// `const_new` will not be instrumented. As such, it will not be visible
/// in [`tokio-console`]. Instead, [`Notify::new`] should be used to create
/// an instrumented object if that is needed.
///
/// # Examples
///
/// ```
/// use tokio::sync::Notify;
///
/// static NOTIFY: Notify = Notify::const_new();
/// ```
///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new() -> Notify {
Notify {
Expand Down
16 changes: 16 additions & 0 deletions tokio/src/sync/once_cell.rs
Expand Up @@ -153,6 +153,11 @@ impl<T> OnceCell<T> {
///
/// # Example
///
/// When using the `tracing` [unstable feature], a `OnceCell` created with
/// `const_new_with` will not be instrumented. As such, it will not be
/// visible in [`tokio-console`]. Instead, [`OnceCell::new_with`] should be
/// used to create an instrumented object if that is needed.
///
/// ```
/// use tokio::sync::OnceCell;
///
Expand All @@ -170,6 +175,9 @@ impl<T> OnceCell<T> {
/// assert_eq!(*result, 1);
/// }
/// ```
///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new_with(value: T) -> Self {
OnceCell {
Expand All @@ -184,6 +192,11 @@ impl<T> OnceCell<T> {
/// Equivalent to `OnceCell::new`, except that it can be used in static
/// variables.
///
/// When using the `tracing` [unstable feature], a `OnceCell` created with
/// `const_new` will not be instrumented. As such, it will not be visible
/// in [`tokio-console`]. Instead, [`OnceCell::new`] should be used to
/// create an instrumented object if that is needed.
///
/// # Example
///
/// ```
Expand All @@ -203,6 +216,9 @@ impl<T> OnceCell<T> {
/// assert_eq!(*result, 2);
/// }
/// ```
///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new() -> Self {
OnceCell {
Expand Down
8 changes: 8 additions & 0 deletions tokio/src/sync/rwlock.rs
Expand Up @@ -327,13 +327,21 @@ impl<T: ?Sized> RwLock<T> {

/// Creates a new instance of an `RwLock<T>` which is unlocked.
///
/// When using the `tracing` [unstable feature], a `RwLock` created with
/// `const_new` will not be instrumented. As such, it will not be visible
/// in [`tokio-console`]. Instead, [`RwLock::new`] should be used to create
/// an instrumented object if that is needed.
///
/// # Examples
///
/// ```
/// use tokio::sync::RwLock;
///
/// static LOCK: RwLock<i32> = RwLock::const_new(5);
/// ```
///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new(value: T) -> RwLock<T>
where
Expand Down
8 changes: 8 additions & 0 deletions tokio/src/sync/semaphore.rs
Expand Up @@ -194,13 +194,21 @@ impl Semaphore {

/// Creates a new semaphore with the initial number of permits.
///
/// When using the `tracing` [unstable feature], a `Semaphore` created with
/// `const_new` will not be instrumented. As such, it will not be visible
/// in [`tokio-console`]. Instead, [`Semaphore::new`] should be used to
/// create an instrumented object if that is needed.
///
/// # Examples
///
/// ```
/// use tokio::sync::Semaphore;
///
/// static SEM: Semaphore = Semaphore::const_new(10);
/// ```
///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new(permits: usize) -> Self {
Self {
Expand Down