diff options
| author | bors <bors@rust-lang.org> | 2019-03-22 21:00:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-03-22 21:00:07 +0000 |
| commit | 9f91bee03f3eea93285330354dda54706028671c (patch) | |
| tree | 0b8cb0de7ea1416081cfa16e36ea400a9d966498 /src/libstd/thread | |
| parent | cb2f34dc6d7e83d8bcfef79e0388d49f0c24aca7 (diff) | |
| parent | cf8c73936d48560b50d98a299c98fd35e5b4581e (diff) | |
| download | rust-9f91bee03f3eea93285330354dda54706028671c.tar.gz rust-9f91bee03f3eea93285330354dda54706028671c.zip | |
Auto merge of #59370 - Centril:rollup, r=Centril
Rollup of 18 pull requests Successful merges: - #59106 (Add peer_addr function to UdpSocket) - #59170 (Add const generics to rustdoc) - #59172 (Update and clean up several parts of CONTRIBUTING.md) - #59190 (consistent naming for Rhs type parameter in libcore/ops) - #59236 (Rename miri component to miri-preview) - #59266 (Do not complain about non-existing fields after parse recovery) - #59273 (some small HIR doc improvements) - #59291 (Make Option<ThreadId> no larger than ThreadId, with NonZeroU64) - #59297 (convert field/method confusion help to suggestions) - #59304 (Move some bench tests back from libtest) - #59309 (Add messages for different verbosity levels. Output copy actions.) - #59321 (Unify E0109, E0110 and E0111) - #59322 (Tweak incorrect escaped char diagnostic) - #59323 (use suggestions for "enum instead of variant" error) - #59327 (Add NAN test to docs) - #59329 (cleanup: Remove compile-fail-fulldeps directory again) - #59347 (Move one test from run-make-fulldeps to ui) - #59360 (Add tracking issue number for `seek_convenience`) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 08f0aa2f0d2..d856f9b465e 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()) } } } @@ -1484,9 +1485,10 @@ fn _assert_sync_and_send() { mod tests { use super::Builder; use crate::any::Any; + use crate::mem; use crate::sync::mpsc::{channel, Sender}; use crate::result; - use crate::thread; + use crate::thread::{self, ThreadId}; use crate::time::Duration; use crate::u32; @@ -1717,6 +1719,11 @@ mod tests { } #[test] + fn test_size_of_option_thread_id() { + assert_eq!(mem::size_of::<Option<ThreadId>>(), mem::size_of::<ThreadId>()); + } + + #[test] fn test_thread_id_equal() { assert!(thread::current().id() == thread::current().id()); } |
