-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
rt: add runtime Id #5864
Merged
Merged
rt: add runtime Id #5864
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6615423
rt: add runtime Id
hds a9a5e11
use the `OwnedTasks` and `LocalOwnedTasks` ids
hds 139c7c7
fix visibility of methods only needed for unstable
hds 370e145
Merge remote-tracking branch 'origin' into hds/runtime-id
hds 9a0ee60
adapt runtime ID to use `NonZeroU64`
hds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::fmt; | ||
use std::num::NonZeroU64; | ||
|
||
/// An opaque ID that uniquely identifies a runtime relative to all other currently | ||
/// running runtimes. | ||
/// | ||
/// # Notes | ||
/// | ||
/// - Runtime IDs are unique relative to other *currently running* runtimes. | ||
/// When a runtime completes, the same ID may be used for another runtime. | ||
/// - Runtime IDs are *not* sequential, and do not indicate the order in which | ||
/// runtimes are started or any other data. | ||
/// - The runtime ID of the currently running task can be obtained from the | ||
/// Handle. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use tokio::runtime::Handle; | ||
/// | ||
/// #[tokio::main(flavor = "multi_thread", worker_threads = 4)] | ||
/// async fn main() { | ||
/// println!("Current runtime id: {}", Handle::current().id()); | ||
/// } | ||
/// ``` | ||
/// | ||
/// **Note**: This is an [unstable API][unstable]. The public API of this type | ||
/// may break in 1.x releases. See [the documentation on unstable | ||
/// features][unstable] for details. | ||
/// | ||
/// [unstable]: crate#unstable-features | ||
#[cfg_attr(not(tokio_unstable), allow(unreachable_pub))] | ||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] | ||
pub struct Id(NonZeroU64); | ||
|
||
impl From<NonZeroU64> for Id { | ||
fn from(value: NonZeroU64) -> Self { | ||
Id(value) | ||
} | ||
} | ||
|
||
impl fmt::Display for Id { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Whether merge all taskid/threadid/runtimeid as one type id?
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.
Keeping a separate type because we don't want users to be able to compare (for example) a task ID to a runtime ID. Also, the
runtime::Id
implementation is now pretty different as we're using the value from the (Local
)OwnedTasks
ID.