]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #70240 - brain0:thread_id, r=Mark-Simulacrum
authorDylan DPC <dylan.dpc@gmail.com>
Sun, 22 Mar 2020 14:48:37 +0000 (15:48 +0100)
committerGitHub <noreply@github.com>
Sun, 22 Mar 2020 14:48:37 +0000 (15:48 +0100)
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.

src/librustc_data_structures/profiling.rs
src/libstd/thread/mod.rs

index a70314c35c07c9cee94c035162425c6b3fe39fd8..a7cdc48d60342f986c4e4a5e2ff3333bc2a3f3ac 100644 (file)
@@ -345,7 +345,7 @@ fn instant_query_event(
     ) {
         drop(self.exec(event_filter, |profiler| {
             let event_id = StringId::new_virtual(query_invocation_id.0);
-            let thread_id = std::thread::current().id().as_u64() as u32;
+            let thread_id = std::thread::current().id().as_u64().get() as u32;
 
             profiler.profiler.record_instant_event(
                 event_kind(profiler),
@@ -522,7 +522,7 @@ pub fn start(
         event_kind: StringId,
         event_id: EventId,
     ) -> TimingGuard<'a> {
-        let thread_id = std::thread::current().id().as_u64() as u32;
+        let thread_id = std::thread::current().id().as_u64().get() as u32;
         let raw_profiler = &profiler.profiler;
         let timing_guard =
             raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id);
index 0dc43c7e6510ab6abac48de6ff4ef722b0f6514a..282e268efd20686f35fba68a792d3f4f96ce432e 100644 (file)
@@ -1082,8 +1082,8 @@ fn new() -> ThreadId {
     /// it is not guaranteed which values new threads will return, and this may
     /// change across Rust versions.
     #[unstable(feature = "thread_id_value", issue = "67939")]
-    pub fn as_u64(&self) -> u64 {
-        self.0.get()
+    pub fn as_u64(&self) -> NonZeroU64 {
+        self.0
     }
 }