Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1b3fe75
Allow simd_shuffle to accept vectors of any length
calebzulawski Sep 11, 2021
37196e3
Suggest replacing an inexisting field for an unmentioned field
hkmatsumoto Aug 12, 2021
ffdabc8
Check for shadowing issues involving block labels
tmiasko Sep 15, 2021
bd4c967
Fix linting when trailing macro expands to a trailing semi
Aaron1011 Sep 16, 2021
4a4ca94
Fix shuffle index constant not being monomorphized.
calebzulawski Sep 16, 2021
2b512cc
fix potential race in AtomicU64 time monotonizer
the8472 Sep 16, 2021
f84000d
Add a separate error for `dyn Trait` in `const fn`
WaffleLapkin Sep 16, 2021
57465d9
use AtomicU64::fetch_update instead of handrolled RMW-loop
the8472 Sep 17, 2021
ec34aa6
modify std::os docs to be more consistent
schctl Sep 17, 2021
05b01cd
refactor: VecDeques IntoIter fields to private
DeveloperC286 Sep 17, 2021
68147eb
Suggest better place to add call parentheses for method expressions w…
Kobzol Sep 17, 2021
3f75ab3
Fix typo
Sep 18, 2021
ebd31f5
Rollup merge of #87960 - hkmatsumoto:suggest-inexisting-field-for-unm…
JohnTitor Sep 19, 2021
e675073
Rollup merge of #88855 - calebzulawski:feature/simd_shuffle, r=nagisa
JohnTitor Sep 19, 2021
ba1a90a
Rollup merge of #88966 - tmiasko:block-label-shadowing, r=petrochenkov
JohnTitor Sep 19, 2021
1c3fce0
Rollup merge of #88996 - Aaron1011:trailing-macro-semi, r=petrochenkov
JohnTitor Sep 19, 2021
91c5e7c
Rollup merge of #89017 - the8472:fix-u64-time-monotonizer, r=kennytm
JohnTitor Sep 19, 2021
61bfe36
Rollup merge of #89021 - WaffleLapkin:separate_error_for_dyn_trait_in…
JohnTitor Sep 19, 2021
4366059
Rollup merge of #89051 - schctl:master, r=jyn514
JohnTitor Sep 19, 2021
e4dbe27
Rollup merge of #89053 - DeveloperC286:into_iter_fields_to_private, r…
JohnTitor Sep 19, 2021
441046a
Rollup merge of #89055 - Kobzol:wrapped-method-expr-call-parens, r=we…
JohnTitor Sep 19, 2021
4877ad3
Rollup merge of #89081 - ondra05:patch-1, r=dtolnay
JohnTitor Sep 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix potential race in AtomicU64 time monotonizer
  • Loading branch information
the8472 committed Sep 16, 2021
commit 2b512cc329a87202003d41828fe8f6f2fbeaf720
62 changes: 34 additions & 28 deletions library/std/src/time/monotonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,41 @@ pub mod inner {
// This could be a problem for programs that call instants at intervals greater
// than 68 years. Interstellar probes may want to ensure that actually_monotonic() is true.
let packed = (secs << 32) | nanos;
let old = mono.load(Relaxed);

if old == UNINITIALIZED || packed.wrapping_sub(old) < u64::MAX / 2 {
mono.store(packed, Relaxed);
raw
} else {
// Backslide occurred. We reconstruct monotonized time from the upper 32 bit of the
// passed in value and the 64bits loaded from the atomic
let seconds_lower = old >> 32;
let mut seconds_upper = secs & 0xffff_ffff_0000_0000;
if secs & 0xffff_ffff > seconds_lower {
// Backslide caused the lower 32bit of the seconds part to wrap.
// This must be the case because the seconds part is larger even though
// we are in the backslide branch, i.e. the seconds count should be smaller or equal.
//
// We assume that backslides are smaller than 2^32 seconds
// which means we need to add 1 to the upper half to restore it.
//
// Example:
// most recent observed time: 0xA1_0000_0000_0000_0000u128
// bits stored in AtomicU64: 0x0000_0000_0000_0000u64
// backslide by 1s
// caller time is 0xA0_ffff_ffff_0000_0000u128
// -> we can fix up the upper half time by adding 1 << 32
seconds_upper = seconds_upper.wrapping_add(0x1_0000_0000);
let mut old = mono.load(Relaxed);
loop {
if old == UNINITIALIZED || packed.wrapping_sub(old) < u64::MAX / 2 {
match mono.compare_exchange_weak(old, packed, Relaxed, Relaxed) {
Ok(_) => return raw,
Err(x) => {
old = x;
continue;
}
}
} else {
// Backslide occurred. We reconstruct monotonized time from the upper 32 bit of the
// passed in value and the 64bits loaded from the atomic
let seconds_lower = old >> 32;
let mut seconds_upper = secs & 0xffff_ffff_0000_0000;
if secs & 0xffff_ffff > seconds_lower {
// Backslide caused the lower 32bit of the seconds part to wrap.
// This must be the case because the seconds part is larger even though
// we are in the backslide branch, i.e. the seconds count should be smaller or equal.
//
// We assume that backslides are smaller than 2^32 seconds
// which means we need to add 1 to the upper half to restore it.
//
// Example:
// most recent observed time: 0xA1_0000_0000_0000_0000u128
// bits stored in AtomicU64: 0x0000_0000_0000_0000u64
// backslide by 1s
// caller time is 0xA0_ffff_ffff_0000_0000u128
// -> we can fix up the upper half time by adding 1 << 32
seconds_upper = seconds_upper.wrapping_add(0x1_0000_0000);
}
let secs = seconds_upper | seconds_lower;
let nanos = old as u32;
return ZERO.checked_add_duration(&Duration::new(secs, nanos)).unwrap();
}
let secs = seconds_upper | seconds_lower;
let nanos = old as u32;
ZERO.checked_add_duration(&Duration::new(secs, nanos)).unwrap()
}
}
}
Expand Down