Skip to contentSkip to conversation

lockref: Relax in cmpxchg loop

PATCH New Luck, Tony 1 participant 1 message Sep 3, 2013 Library code

lore
Share & tools
lore

Luck, Tony

author
#0 lore raw

PATCH 1/1 lockref: Relax in cmpxchg loop

While we are likley to succeed and break out of this loop, it isn't guaranteed. We should be power and thread friendly if we do have to go around for a second (or third, or more) attempt.

---

lib/lockref.c +1 -0
index 7819c2d..9d76f40 100644
@@ -19,6 +19,7 @@
 		if (likely(old.lock_count == prev.lock_count)) {		\
 			SUCCESS;						\
 		}								\
+		cpu_relax();							\
 	}									\
 } while (0)
 
Signature · 1 line
1.8.1.4