On 04/19/2016 04:07 PM, Emilio G. Cota wrote:
From: Guillaume Delbergue <guillaume.delber...@greensocs.com>

Signed-off-by: Guillaume Delbergue <guillaume.delber...@greensocs.com>
[Rewritten. - Paolo]
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
[Emilio's additions: call cpu_relax() while spinning; optimize for
  uncontended locks by acquiring the lock with xchg+test instead of
  test+xchg+test.]
Signed-off-by: Emilio G. Cota <c...@braap.org>
---

It probably doesn't matter for any real hosts, but do note that there are compiler primitives for test-and-set that (can be) simpler for a cpu to implement than xchg. This likely affects only ancient hosts like sparcv7,
or tiny hosts like SH.

We don't have to change anything here, but it does seem more natural to use a test-and-set primitive.

+static inline int qemu_spin_trylock(QemuSpin *spin)
+{
+    if (atomic_read(&spin->value) || atomic_xchg(&spin->value, true)) {
+        return -EBUSY;

I think there's no point in the extra read here.


r~

Reply via email to