2 * arch/s390/lib/spinlock.c
3 * Out of line spinlock code.
5 * Copyright (C) IBM Corp. 2004, 2006
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
9 #include <linux/types.h>
10 #include <linux/module.h>
11 #include <linux/spinlock.h>
12 #include <linux/init.h>
15 int spin_retry
= 1000;
18 * spin_retry= parameter
20 static int __init
spin_retry_setup(char *str
)
22 spin_retry
= simple_strtoul(str
, &str
, 0);
25 __setup("spin_retry=", spin_retry_setup
);
31 if (MACHINE_HAS_DIAG44
)
33 asm volatile("diag 0,0,0x44");
37 _raw_spin_lock_wait(raw_spinlock_t
*lp
, unsigned int pc
)
39 int count
= spin_retry
;
46 if (__raw_spin_is_locked(lp
))
48 if (_raw_compare_and_swap(&lp
->lock
, 0, pc
) == 0)
52 EXPORT_SYMBOL(_raw_spin_lock_wait
);
55 _raw_spin_trylock_retry(raw_spinlock_t
*lp
, unsigned int pc
)
57 int count
= spin_retry
;
60 if (__raw_spin_is_locked(lp
))
62 if (_raw_compare_and_swap(&lp
->lock
, 0, pc
) == 0)
67 EXPORT_SYMBOL(_raw_spin_trylock_retry
);
70 _raw_read_lock_wait(raw_rwlock_t
*rw
)
73 int count
= spin_retry
;
80 if (!__raw_read_can_lock(rw
))
82 old
= rw
->lock
& 0x7fffffffU
;
83 if (_raw_compare_and_swap(&rw
->lock
, old
, old
+ 1) == old
)
87 EXPORT_SYMBOL(_raw_read_lock_wait
);
90 _raw_read_trylock_retry(raw_rwlock_t
*rw
)
93 int count
= spin_retry
;
96 if (!__raw_read_can_lock(rw
))
98 old
= rw
->lock
& 0x7fffffffU
;
99 if (_raw_compare_and_swap(&rw
->lock
, old
, old
+ 1) == old
)
104 EXPORT_SYMBOL(_raw_read_trylock_retry
);
107 _raw_write_lock_wait(raw_rwlock_t
*rw
)
109 int count
= spin_retry
;
116 if (!__raw_write_can_lock(rw
))
118 if (_raw_compare_and_swap(&rw
->lock
, 0, 0x80000000) == 0)
122 EXPORT_SYMBOL(_raw_write_lock_wait
);
125 _raw_write_trylock_retry(raw_rwlock_t
*rw
)
127 int count
= spin_retry
;
129 while (count
-- > 0) {
130 if (!__raw_write_can_lock(rw
))
132 if (_raw_compare_and_swap(&rw
->lock
, 0, 0x80000000) == 0)
137 EXPORT_SYMBOL(_raw_write_trylock_retry
);