Commit 25addffe authored by Paul Mackerras's avatar Paul Mackerras

PPC32: add __down_read_trylock and __down_write_trylock implementations.

parent c6c91a46
...@@ -72,12 +72,26 @@ static inline void init_rwsem(struct rw_semaphore *sem) ...@@ -72,12 +72,26 @@ static inline void init_rwsem(struct rw_semaphore *sem)
*/ */
static inline void __down_read(struct rw_semaphore *sem) static inline void __down_read(struct rw_semaphore *sem)
{ {
if (atomic_inc_return((atomic_t *)(&sem->count)) >= 0) if (atomic_inc_return((atomic_t *)(&sem->count)) > 0)
smp_wmb(); smp_wmb();
else else
rwsem_down_read_failed(sem); rwsem_down_read_failed(sem);
} }
static inline int __down_read_trylock(struct rw_semaphore *sem)
{
int tmp;
while ((tmp = sem->count) >= 0) {
if (tmp == cmpxchg(&sem->count, tmp,
tmp + RWSEM_ACTIVE_READ_BIAS)) {
smp_wmb();
return 1;
}
}
return 0;
}
/* /*
* lock for writing * lock for writing
*/ */
...@@ -93,6 +107,16 @@ static inline void __down_write(struct rw_semaphore *sem) ...@@ -93,6 +107,16 @@ static inline void __down_write(struct rw_semaphore *sem)
rwsem_down_write_failed(sem); rwsem_down_write_failed(sem);
} }
static inline int __down_write_trylock(struct rw_semaphore *sem)
{
int tmp;
tmp = cmpxchg(&sem->count, RWSEM_UNLOCKED_VALUE,
RWSEM_ACTIVE_WRITE_BIAS);
smp_wmb();
return tmp == RWSEM_UNLOCKED_VALUE;
}
/* /*
* unlock after reading * unlock after reading
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment