Skip to content

Commit

Permalink
Merge #166
Browse files Browse the repository at this point in the history
166: We don't need to build an inner loop when we can reuse the outer loop. r=ptersilie a=ltratt

This is also safer since it deals with the possibility that another thread has started tracing this location.

Co-authored-by: Laurence Tratt <laurie@tratt.net>
bors[bot] and ltratt authored Dec 4, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 1c39c63 + 879b382 commit ae5c029
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions ykrt/src/mt.rs
Original file line number Diff line number Diff line change
@@ -228,10 +228,10 @@ impl MTThread {
loop {
// We need Acquire ordering, as PHASE_COMPILED will need to read information written to
// external data as a result of the PHASE_TRACING -> PHASE_COMPILED transition.
let mut lp = loc.pack.load(Ordering::Acquire);
let lp = loc.pack.load(Ordering::Acquire);
match lp & PHASE_TAG {
PHASE_COUNTING => {
let mut count = (lp & !PHASE_TAG) >> 2;
let count = (lp & !PHASE_TAG) >> 2;
if count >= self.inner.hot_threshold {
if self.inner.tracer.is_some() {
// This thread is already tracing. Note that we don't increment the hot
@@ -250,19 +250,12 @@ impl MTThread {
unsafe { Box::from_raw(loc_id) };
}
} else {
loop {
let new_pack = PHASE_COUNTING | ((count + 1) << PHASE_NUM_BITS);
if loc.pack.compare_and_swap(lp, new_pack, Ordering::Release) == lp {
return None;
}
// We raced with another thread, but we'd still like to try
// incrementing the count if possible, so we try again.
lp = loc.pack.load(Ordering::Acquire);
count = (lp & !PHASE_TAG) >> 2;
if count >= self.inner.hot_threshold {
break;
}
let new_pack = PHASE_COUNTING | ((count + 1) << PHASE_NUM_BITS);
if loc.pack.compare_and_swap(lp, new_pack, Ordering::Release) == lp {
return None;
}
// We raced with another thread, but we'd still like to try incrementing
// the count if possible, so go around the loop again.
}
}
PHASE_TRACING => {

0 comments on commit ae5c029

Please sign in to comment.