diff -ru4 2.4.1/include/asm-i386/semaphore.h 2.4.1-ben/include/asm-i386/semaphore.h --- 2.4.1/include/asm-i386/semaphore.h Fri Feb 16 18:47:23 2001 +++ 2.4.1-ben/include/asm-i386/semaphore.h Tue Feb 20 14:23:19 2001 @@ -381,6 +381,61 @@ #endif __up_write(sem); } +/* returns 0 if it successfully obtained the semaphore for write */ +static inline int down_write_trylock(struct rw_semaphore *sem) +{ + int old = RW_LOCK_BIAS, new = 0; + +#if WAITQUEUE_DEBUG + if (sem->__magic != (long)&sem->__magic) + BUG(); +#endif + if (cmpxchg(&sem->count.counter, old, new) == RW_LOCK_BIAS) { +#if WAITQUEUE_DEBUG + if (atomic_read(&sem->writers)) + BUG(); + if (atomic_read(&sem->readers)) + BUG(); + if (sem->read_bias_granted) + BUG(); + if (sem->write_bias_granted) + BUG(); + atomic_inc(&sem->writers); +#endif + return 0; + } + else + return 1; +} + +/* returns 0 if it successfully obtained the semaphore for read */ +static inline int down_read_trylock(struct rw_semaphore *sem) +{ + int old, new; + +#if WAITQUEUE_DEBUG + if (sem->__magic != (long)&sem->__magic) + BUG(); +#endif +repeat: + old = atomic_read(&sem->count); + if (old <= 0) + return 1; + new = old - 1; + if (cmpxchg(&sem->count.counter, old, new) == old) { +#if WAITQUEUE_DEBUG + if (sem->write_bias_granted) + BUG(); + if (atomic_read(&sem->writers)) + BUG(); + atomic_inc(&sem->readers); +#endif + return 0; + } + else + goto repeat; +} + #endif #endif