diff options
Diffstat (limited to 'linux/six.c')
-rw-r--r-- | linux/six.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/linux/six.c b/linux/six.c index a47cd6d0..d4f43f15 100644 --- a/linux/six.c +++ b/linux/six.c @@ -118,7 +118,7 @@ static int __do_six_trylock(struct six_lock *lock, enum six_lock_type type, { const struct six_lock_vals l[] = LOCK_VALS; int ret; - u32 old, new, v; + u32 old; EBUG_ON(type == SIX_LOCK_write && lock->owner != task); EBUG_ON(type == SIX_LOCK_write && @@ -179,19 +179,14 @@ static int __do_six_trylock(struct six_lock *lock, enum six_lock_type type, ret = -1 - SIX_LOCK_read; } } else { - v = atomic_read(&lock->state); + old = atomic_read(&lock->state); do { - new = old = v; - ret = !(old & l[type].lock_fail); - if (!ret || (type == SIX_LOCK_write && !try)) { smp_mb(); break; } - - new += l[type].lock_val; - } while ((v = atomic_cmpxchg_acquire(&lock->state, old, new)) != old); + } while (!atomic_try_cmpxchg_acquire(&lock->state, &old, old + l[type].lock_val)); EBUG_ON(ret && !(atomic_read(&lock->state) & l[type].held_mask)); } @@ -681,10 +676,10 @@ EXPORT_SYMBOL_GPL(six_lock_downgrade); bool six_lock_tryupgrade(struct six_lock *lock) { const struct six_lock_vals l[] = LOCK_VALS; - u32 old, new, v = atomic_read(&lock->state); + u32 old = atomic_read(&lock->state), new; do { - new = old = v; + new = old; if (new & SIX_LOCK_HELD_intent) return false; @@ -695,7 +690,7 @@ bool six_lock_tryupgrade(struct six_lock *lock) } new |= SIX_LOCK_HELD_intent; - } while ((v = atomic_cmpxchg_acquire(&lock->state, old, new)) != old); + } while (!atomic_try_cmpxchg_acquire(&lock->state, &old, new)); if (lock->readers) this_cpu_dec(*lock->readers); |