Rollup merge of #91176 - hermitcore:spin, r=kennytm
If the thread does not get the lock in the short term, yield the CPU Reduces on [RustyHermit](https://github.com/hermitcore/rusty-hermit) the amount of wasted processor cycles
This commit is contained in:
commit
fdc305d58d
1 changed files with 10 additions and 1 deletions
|
@ -46,8 +46,17 @@ impl<T> Spinlock<T> {
|
|||
#[inline]
|
||||
fn obtain_lock(&self) {
|
||||
let ticket = self.queue.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
let mut counter: u16 = 0;
|
||||
while self.dequeue.load(Ordering::SeqCst) != ticket {
|
||||
hint::spin_loop();
|
||||
counter += 1;
|
||||
if counter < 100 {
|
||||
hint::spin_loop();
|
||||
} else {
|
||||
counter = 0;
|
||||
unsafe {
|
||||
abi::yield_now();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue