about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2019-03-19 13:59:38 +0100
committerSimon Sapin <simon.sapin@exyr.org>2019-03-19 14:00:13 +0100
commit8cf720bd19a00f52e3db630947f6424946ee0f6c (patch)
tree4bb45324b67e3fb9f2cdf8bdfbddbc3cc2ea8529 /src/libstd/thread
parent0f88167f89fffe321590c5148f21b7d51d44388d (diff)
downloadrust-8cf720bd19a00f52e3db630947f6424946ee0f6c.tar.gz
rust-8cf720bd19a00f52e3db630947f6424946ee0f6c.zip
Make Option<ThreadId> no larger than ThreadId, with NonZeroU64
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index 08f0aa2f0d2..40682da8f8b 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -163,6 +163,7 @@ use crate::ffi::{CStr, CString};
 use crate::fmt;
 use crate::io;
 use crate::mem;
+use crate::num::NonZeroU64;
 use crate::panic;
 use crate::panicking;
 use crate::str;
@@ -1036,7 +1037,7 @@ pub fn park_timeout(dur: Duration) {
 /// [`Thread`]: ../../std/thread/struct.Thread.html
 #[stable(feature = "thread_id", since = "1.19.0")]
 #[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)]
-pub struct ThreadId(u64);
+pub struct ThreadId(NonZeroU64);
 
 impl ThreadId {
     // Generate a new unique thread ID.
@@ -1044,7 +1045,7 @@ impl ThreadId {
         // We never call `GUARD.init()`, so it is UB to attempt to
         // acquire this mutex reentrantly!
         static GUARD: mutex::Mutex = mutex::Mutex::new();
-        static mut COUNTER: u64 = 0;
+        static mut COUNTER: u64 = 1;
 
         unsafe {
             let _guard = GUARD.lock();
@@ -1058,7 +1059,7 @@ impl ThreadId {
             let id = COUNTER;
             COUNTER += 1;
 
-            ThreadId(id)
+            ThreadId(NonZeroU64::new(id).unwrap())
         }
     }
 }