Skip to content

Commit 64c734e

Browse files
committed
runtime: expose Builder::rng_seed without tokio_unstable
Moves `Builder::rng_seed`, the `runtime::RngSeed` re-export, and `RngSeed::from_bytes` out of `cfg_unstable!` so callers can seed the scheduler RNG (and thus get deterministic `select!` branch ordering) without `--cfg tokio_unstable`. The underlying `seed_generator` field and all runtime plumbing were already unconditional; only the public setter and type re-export were gated. No behavior change for builds that already set `tokio_unstable`. Upstream tracking issue: tokio-rs#4879 (introduced in tokio-rs#4910).
1 parent 8b6e427 commit 64c734e

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

tokio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "tokio"
66
# - README.md
77
# - Update CHANGELOG.md.
88
# - Create "v1.x.y" git tag.
9-
version = "1.49.0+anthropic.1"
9+
version = "1.49.0+anthropic.2"
1010
edition = "2021"
1111
rust-version = "1.71"
1212
authors = ["Tokio Contributors <team@tokio.rs>"]

tokio/src/runtime/builder.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,39 +1412,39 @@ impl Builder {
14121412
self.disable_lifo_slot = true;
14131413
self
14141414
}
1415+
}
14151416

1416-
/// Specifies the random number generation seed to use within all
1417-
/// threads associated with the runtime being built.
1418-
///
1419-
/// This option is intended to make certain parts of the runtime
1420-
/// deterministic (e.g. the [`tokio::select!`] macro). In the case of
1421-
/// [`tokio::select!`] it will ensure that the order that branches are
1422-
/// polled is deterministic.
1423-
///
1424-
/// In addition to the code specifying `rng_seed` and interacting with
1425-
/// the runtime, the internals of Tokio and the Rust compiler may affect
1426-
/// the sequences of random numbers. In order to ensure repeatable
1427-
/// results, the version of Tokio, the versions of all other
1428-
/// dependencies that interact with Tokio, and the Rust compiler version
1429-
/// should also all remain constant.
1430-
///
1431-
/// # Examples
1432-
///
1433-
/// ```
1434-
/// # use tokio::runtime::{self, RngSeed};
1435-
/// # pub fn main() {
1436-
/// let seed = RngSeed::from_bytes(b"place your seed here");
1437-
/// let rt = runtime::Builder::new_current_thread()
1438-
/// .rng_seed(seed)
1439-
/// .build();
1440-
/// # }
1441-
/// ```
1442-
///
1443-
/// [`tokio::select!`]: crate::select
1444-
pub fn rng_seed(&mut self, seed: RngSeed) -> &mut Self {
1445-
self.seed_generator = RngSeedGenerator::new(seed);
1446-
self
1447-
}
1417+
/// Specifies the random number generation seed to use within all
1418+
/// threads associated with the runtime being built.
1419+
///
1420+
/// This option is intended to make certain parts of the runtime
1421+
/// deterministic (e.g. the [`tokio::select!`] macro). In the case of
1422+
/// [`tokio::select!`] it will ensure that the order that branches are
1423+
/// polled is deterministic.
1424+
///
1425+
/// In addition to the code specifying `rng_seed` and interacting with
1426+
/// the runtime, the internals of Tokio and the Rust compiler may affect
1427+
/// the sequences of random numbers. In order to ensure repeatable
1428+
/// results, the version of Tokio, the versions of all other
1429+
/// dependencies that interact with Tokio, and the Rust compiler version
1430+
/// should also all remain constant.
1431+
///
1432+
/// # Examples
1433+
///
1434+
/// ```
1435+
/// # use tokio::runtime::{self, RngSeed};
1436+
/// # pub fn main() {
1437+
/// let seed = RngSeed::from_bytes(b"place your seed here");
1438+
/// let rt = runtime::Builder::new_current_thread()
1439+
/// .rng_seed(seed)
1440+
/// .build();
1441+
/// # }
1442+
/// ```
1443+
///
1444+
/// [`tokio::select!`]: crate::select
1445+
pub fn rng_seed(&mut self, seed: RngSeed) -> &mut Self {
1446+
self.seed_generator = RngSeedGenerator::new(seed);
1447+
self
14481448
}
14491449

14501450
cfg_unstable_metrics! {

tokio/src/runtime/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ cfg_rt! {
550550

551551
mod builder;
552552
pub use self::builder::Builder;
553+
pub use crate::util::rand::RngSeed;
553554
cfg_unstable! {
554555
pub use self::builder::UnhandledPanic;
555-
pub use crate::util::rand::RngSeed;
556556

557557
mod local_runtime;
558558
pub use local_runtime::{LocalRuntime, LocalOptions};

tokio/src/util/rand.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ cfg_rt! {
22
mod rt;
33
pub(crate) use rt::RngSeedGenerator;
44

5-
cfg_unstable! {
6-
mod rt_unstable;
7-
}
5+
mod rt_unstable;
86
}
97

108
/// A seed for random number generation.

0 commit comments

Comments
 (0)