Skip to content

Commit c8140a8

Browse files
author
Thomas Bächler
committed
Return NonZeroU64 from ThreadId::as_u64.
As discussed in #67939, this allows turning Option<ThreadId> into Option<NonZeroU64> which can then be stored inside an AtomicU64.
1 parent 98803c1 commit c8140a8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/librustc_data_structures/profiling.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl SelfProfilerRef {
345345
) {
346346
drop(self.exec(event_filter, |profiler| {
347347
let event_id = StringId::new_virtual(query_invocation_id.0);
348-
let thread_id = std::thread::current().id().as_u64() as u32;
348+
let thread_id = std::thread::current().id().as_u64().get() as u32;
349349

350350
profiler.profiler.record_instant_event(
351351
event_kind(profiler),
@@ -522,7 +522,7 @@ impl<'a> TimingGuard<'a> {
522522
event_kind: StringId,
523523
event_id: EventId,
524524
) -> TimingGuard<'a> {
525-
let thread_id = std::thread::current().id().as_u64() as u32;
525+
let thread_id = std::thread::current().id().as_u64().get() as u32;
526526
let raw_profiler = &profiler.profiler;
527527
let timing_guard =
528528
raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id);

src/libstd/thread/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,8 @@ impl ThreadId {
10821082
/// it is not guaranteed which values new threads will return, and this may
10831083
/// change across Rust versions.
10841084
#[unstable(feature = "thread_id_value", issue = "67939")]
1085-
pub fn as_u64(&self) -> u64 {
1086-
self.0.get()
1085+
pub fn as_u64(&self) -> NonZeroU64 {
1086+
self.0
10871087
}
10881088
}
10891089

0 commit comments

Comments
 (0)