2 * arch/s390/lib/spinlock.c
3 * Out of line spinlock code.
6 * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
10 #include <linux/types.h>
11 #include <linux/module.h>
12 #include <linux/spinlock.h>
13 #include <linux/init.h>
16 atomic_t spin_retry_counter
;
17 int spin_retry
= 1000;
20 * spin_retry= parameter
22 static int __init
spin_retry_setup(char *str
)
24 spin_retry
= simple_strtoul(str
, &str
, 0);
27 __setup("spin_retry=", spin_retry_setup
);
33 if (MACHINE_HAS_DIAG44
)
35 asm volatile("diag 0,0,0x44");
39 _raw_spin_lock_wait(spinlock_t
*lp
, unsigned int pc
)
41 int count
= spin_retry
;
48 atomic_inc(&spin_retry_counter
);
49 if (_raw_compare_and_swap(&lp
->lock
, 0, pc
) == 0)
53 EXPORT_SYMBOL(_raw_spin_lock_wait
);
56 _raw_spin_trylock_retry(spinlock_t
*lp
, unsigned int pc
)
58 int count
= spin_retry
;
61 atomic_inc(&spin_retry_counter
);
62 if (_raw_compare_and_swap(&lp
->lock
, 0, pc
) == 0)
67 EXPORT_SYMBOL(_raw_spin_trylock_retry
);
70 _raw_read_lock_wait(rwlock_t
*rw
)
73 int count
= spin_retry
;
80 atomic_inc(&spin_retry_counter
);
81 old
= rw
->lock
& 0x7fffffffU
;
82 if (_raw_compare_and_swap(&rw
->lock
, old
, old
+ 1) == old
)
86 EXPORT_SYMBOL(_raw_read_lock_wait
);
89 _raw_read_trylock_retry(rwlock_t
*rw
)
92 int count
= spin_retry
;
95 atomic_inc(&spin_retry_counter
);
96 old
= rw
->lock
& 0x7fffffffU
;
97 if (_raw_compare_and_swap(&rw
->lock
, old
, old
+ 1) == old
)
102 EXPORT_SYMBOL(_raw_read_trylock_retry
);
105 _raw_write_lock_wait(rwlock_t
*rw
)
107 int count
= spin_retry
;
114 atomic_inc(&spin_retry_counter
);
115 if (_raw_compare_and_swap(&rw
->lock
, 0, 0x80000000) == 0)
119 EXPORT_SYMBOL(_raw_write_lock_wait
);
122 _raw_write_trylock_retry(rwlock_t
*rw
)
124 int count
= spin_retry
;
126 while (count
-- > 0) {
127 atomic_inc(&spin_retry_counter
);
128 if (_raw_compare_and_swap(&rw
->lock
, 0, 0x80000000) == 0)
133 EXPORT_SYMBOL(_raw_write_trylock_retry
);