Merge pull request #725 from garypen/main
change HokmaLock::write() to use atomic compare_exchange
This commit is contained in:
commit
55a1daee98
@ -50,10 +50,12 @@ impl HokmaLock {
|
|||||||
|
|
||||||
pub fn write(&'static self) -> WhenTheHokmaSuppression {
|
pub fn write(&'static self) -> WhenTheHokmaSuppression {
|
||||||
loop {
|
loop {
|
||||||
let previous = self.lock.load(Ordering::SeqCst);
|
// We are only interested in error results
|
||||||
self.lock.store(1, Ordering::SeqCst);
|
if let Err(previous) = self
|
||||||
|
.lock
|
||||||
if previous != 1 {
|
.compare_exchange(1, 1, Ordering::SeqCst, Ordering::SeqCst)
|
||||||
|
{
|
||||||
|
// If we failed, previous cannot be 1
|
||||||
return WhenTheHokmaSuppression {
|
return WhenTheHokmaSuppression {
|
||||||
hokma: self,
|
hokma: self,
|
||||||
state: previous,
|
state: previous,
|
||||||
|
Loading…
Reference in New Issue
Block a user