summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys_common
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /library/std/src/sys_common
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/std/src/sys_common')
-rw-r--r--library/std/src/sys_common/backtrace.rs19
-rw-r--r--library/std/src/sys_common/thread_info.rs1
-rw-r--r--library/std/src/sys_common/thread_parking/id.rs17
-rw-r--r--library/std/src/sys_common/wtf8.rs17
4 files changed, 42 insertions, 12 deletions
diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs
index 6f020940d..84e2c5d8d 100644
--- a/library/std/src/sys_common/backtrace.rs
+++ b/library/std/src/sys_common/backtrace.rs
@@ -60,6 +60,8 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
bt_fmt.add_context()?;
let mut idx = 0;
let mut res = Ok(());
+ let mut omitted_count: usize = 0;
+ let mut first_omit = true;
// Start immediately if we're not using a short backtrace.
let mut start = print_fmt != PrintFmt::Short;
backtrace_rs::trace_unsynchronized(|frame| {
@@ -85,10 +87,27 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
start = true;
return;
}
+ if !start {
+ omitted_count += 1;
+ }
}
}
if start {
+ if omitted_count > 0 {
+ debug_assert!(print_fmt == PrintFmt::Short);
+ // only print the message between the middle of frames
+ if !first_omit {
+ let _ = writeln!(
+ bt_fmt.formatter(),
+ " [... omitted {} frame{} ...]",
+ omitted_count,
+ if omitted_count > 1 { "s" } else { "" }
+ );
+ }
+ first_omit = false;
+ omitted_count = 0;
+ }
res = bt_fmt.frame().symbol(frame, symbol);
}
});
diff --git a/library/std/src/sys_common/thread_info.rs b/library/std/src/sys_common/thread_info.rs
index 38c9e5000..88d937a7d 100644
--- a/library/std/src/sys_common/thread_info.rs
+++ b/library/std/src/sys_common/thread_info.rs
@@ -1,5 +1,4 @@
#![allow(dead_code)] // stack_guard isn't used right now on all platforms
-#![allow(unused_unsafe)] // thread_local with `const {}` triggers this liny
use crate::cell::RefCell;
use crate::sys::thread::guard::Guard;
diff --git a/library/std/src/sys_common/thread_parking/id.rs b/library/std/src/sys_common/thread_parking/id.rs
index 15042fc3b..046674396 100644
--- a/library/std/src/sys_common/thread_parking/id.rs
+++ b/library/std/src/sys_common/thread_parking/id.rs
@@ -56,18 +56,14 @@ impl Parker {
self.init_tid();
// Changes NOTIFIED to EMPTY and EMPTY to PARKED.
- let mut state = self.state.fetch_sub(1, Acquire).wrapping_sub(1);
- if state == PARKED {
+ let state = self.state.fetch_sub(1, Acquire);
+ if state == EMPTY {
// Loop to guard against spurious wakeups.
- while state == PARKED {
+ // The state must be reset with acquire ordering to ensure that all
+ // calls to `unpark` synchronize with this thread.
+ while self.state.compare_exchange(NOTIFIED, EMPTY, Acquire, Relaxed).is_err() {
park(self.state.as_ptr().addr());
- state = self.state.load(Acquire);
}
-
- // Since the state change has already been observed with acquire
- // ordering, the state can be reset with a relaxed store instead
- // of a swap.
- self.state.store(EMPTY, Relaxed);
}
}
@@ -78,8 +74,7 @@ impl Parker {
if state == PARKED {
park_timeout(dur, self.state.as_ptr().addr());
// Swap to ensure that we observe all state changes with acquire
- // ordering, even if the state has been changed after the timeout
- // occurred.
+ // ordering.
self.state.swap(EMPTY, Acquire);
}
}
diff --git a/library/std/src/sys_common/wtf8.rs b/library/std/src/sys_common/wtf8.rs
index c9d3e13cf..67db5ebd8 100644
--- a/library/std/src/sys_common/wtf8.rs
+++ b/library/std/src/sys_common/wtf8.rs
@@ -182,6 +182,15 @@ impl Wtf8Buf {
Wtf8Buf { bytes: Vec::with_capacity(capacity), is_known_utf8: true }
}
+ /// Creates a WTF-8 string from a WTF-8 byte vec.
+ ///
+ /// Since the byte vec is not checked for valid WTF-8, this functions is
+ /// marked unsafe.
+ #[inline]
+ pub unsafe fn from_bytes_unchecked(value: Vec<u8>) -> Wtf8Buf {
+ Wtf8Buf { bytes: value, is_known_utf8: false }
+ }
+
/// Creates a WTF-8 string from a UTF-8 `String`.
///
/// This takes ownership of the `String` and does not copy.
@@ -402,6 +411,12 @@ impl Wtf8Buf {
self.bytes.truncate(new_len)
}
+ /// Consumes the WTF-8 string and tries to convert it to a vec of bytes.
+ #[inline]
+ pub fn into_bytes(self) -> Vec<u8> {
+ self.bytes
+ }
+
/// Consumes the WTF-8 string and tries to convert it to UTF-8.
///
/// This does not copy the data.
@@ -444,6 +459,7 @@ impl Wtf8Buf {
/// Converts this `Wtf8Buf` into a boxed `Wtf8`.
#[inline]
pub fn into_box(self) -> Box<Wtf8> {
+ // SAFETY: relies on `Wtf8` being `repr(transparent)`.
unsafe { mem::transmute(self.bytes.into_boxed_slice()) }
}
@@ -496,6 +512,7 @@ impl Extend<CodePoint> for Wtf8Buf {
/// Similar to `&str`, but can additionally contain surrogate code points
/// if they’re not in a surrogate pair.
#[derive(Eq, Ord, PartialEq, PartialOrd)]
+#[repr(transparent)]
pub struct Wtf8 {
bytes: [u8],
}