Skip to content

Commit ea42b1c

Browse files
committed
[self-profiler] Use ThreadId::as_u64() instead of transmute
1 parent 8647aa1 commit ea42b1c

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/librustc_data_structures/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(integer_atomics)]
2424
#![feature(test)]
2525
#![feature(associated_type_bounds)]
26+
#![feature(thread_id_value)]
2627
#![cfg_attr(unix, feature(libc))]
2728
#![allow(rustc::default_hash_types)]
2829

src/librustc_data_structures/profiling.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ use std::fs;
8888
use std::path::Path;
8989
use std::process;
9090
use std::sync::Arc;
91-
use std::thread::ThreadId;
9291
use std::time::{Duration, Instant};
9392
use std::u32;
9493

@@ -149,10 +148,6 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
149148
("query-keys", EventFilter::QUERY_KEYS),
150149
];
151150

152-
fn thread_id_to_u32(tid: ThreadId) -> u32 {
153-
unsafe { std::mem::transmute::<ThreadId, u64>(tid) as u32 }
154-
}
155-
156151
/// Something that uniquely identifies a query invocation.
157152
pub struct QueryInvocationId(pub u32);
158153

@@ -318,7 +313,7 @@ impl SelfProfilerRef {
318313
) {
319314
drop(self.exec(event_filter, |profiler| {
320315
let event_id = StringId::new_virtual(query_invocation_id.0);
321-
let thread_id = thread_id_to_u32(std::thread::current().id());
316+
let thread_id = std::thread::current().id().as_u64() as u32;
322317

323318
profiler.profiler.record_instant_event(
324319
event_kind(profiler),
@@ -477,7 +472,7 @@ impl<'a> TimingGuard<'a> {
477472
event_kind: StringId,
478473
event_id: EventId,
479474
) -> TimingGuard<'a> {
480-
let thread_id = thread_id_to_u32(std::thread::current().id());
475+
let thread_id = std::thread::current().id().as_u64() as u32;
481476
let raw_profiler = &profiler.profiler;
482477
let timing_guard =
483478
raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id);

0 commit comments

Comments
 (0)