From 107bfe5badb795dece336d251f0406580b9b1ac1 Mon Sep 17 00:00:00 2001 From: cynecx Date: Thu, 20 Aug 2020 22:32:21 +0200 Subject: [PATCH] Add spin_loop_hint in `register` spinlock --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 17f87f4..b92e23f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use std::cell::UnsafeCell; use std::fmt; -use std::sync::atomic::AtomicUsize; +use std::sync::atomic::{self, AtomicUsize}; use std::sync::atomic::Ordering::{Acquire, Release, AcqRel}; use std::task::Waker; @@ -330,6 +330,9 @@ impl AtomicWaker { // could also spin here trying to acquire the lock // to register). waker.wake_by_ref(); + + // This is equivalent to a spin lock, so use a spin hint. + atomic::spin_loop_hint(); } state => { // In this case, a concurrent thread is holding the