summaryrefslogtreecommitdiffstats
path: root/arch/tile/lib/spinlock_32.c
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2010-11-25 16:45:43 +0900
committerPaul Mundt <lethal@linux-sh.org>2010-11-25 16:45:43 +0900
commit1ad2096c4eba144522d87541c4024b8c84e95051 (patch)
treea149d469a4da72a7b6e6b777879b740046c4ebc9 /arch/tile/lib/spinlock_32.c
parentc4d73e7d75a54451d6e073c118ba2b8d87bd350d (diff)
parentdf73af86b6e737f357aae85e0b5e621516117780 (diff)
Merge branch 'rmobile/mmcif' into rmobile-latest
Diffstat (limited to 'arch/tile/lib/spinlock_32.c')
-rw-r--r--arch/tile/lib/spinlock_32.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/arch/tile/lib/spinlock_32.c b/arch/tile/lib/spinlock_32.c
index 485e24d62c6..5cd1c4004ec 100644
--- a/arch/tile/lib/spinlock_32.c
+++ b/arch/tile/lib/spinlock_32.c
@@ -167,23 +167,30 @@ void arch_write_lock_slow(arch_rwlock_t *rwlock, u32 val)
* when we compare them.
*/
u32 my_ticket_;
+ u32 iterations = 0;
- /* Take out the next ticket; this will also stop would-be readers. */
- if (val & 1)
- val = get_rwlock(rwlock);
- rwlock->lock = __insn_addb(val, 1 << WR_NEXT_SHIFT);
+ /*
+ * Wait until there are no readers, then bump up the next
+ * field and capture the ticket value.
+ */
+ for (;;) {
+ if (!(val & 1)) {
+ if ((val >> RD_COUNT_SHIFT) == 0)
+ break;
+ rwlock->lock = val;
+ }
+ delay_backoff(iterations++);
+ val = __insn_tns((int *)&rwlock->lock);
+ }
- /* Extract my ticket value from the original word. */
+ /* Take out the next ticket and extract my ticket value. */
+ rwlock->lock = __insn_addb(val, 1 << WR_NEXT_SHIFT);
my_ticket_ = val >> WR_NEXT_SHIFT;
- /*
- * Wait until the "current" field matches our ticket, and
- * there are no remaining readers.
- */
+ /* Wait until the "current" field matches our ticket. */
for (;;) {
u32 curr_ = val >> WR_CURR_SHIFT;
- u32 readers = val >> RD_COUNT_SHIFT;
- u32 delta = ((my_ticket_ - curr_) & WR_MASK) + !!readers;
+ u32 delta = ((my_ticket_ - curr_) & WR_MASK);
if (likely(delta == 0))
break;