diff -ur v2.4.2-pre3/include/asm-i386/semaphore.h trylock/include/asm-i386/semaphore.h --- v2.4.2-pre3/include/asm-i386/semaphore.h Mon Feb 12 16:04:59 2001 +++ trylock/include/asm-i386/semaphore.h Mon Feb 19 23:50:03 2001 @@ -382,5 +382,32 @@ __up_write(sem); } +/* returns 1 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; + int res; + + res = cmpxchg(&sem->count.counter, old, new); + return (res == RW_LOCK_BIAS); +} + +/* returns 1 if it successfully obtained the semaphore for read */ +static inline int down_read_trylock(struct rw_semaphore *sem) +{ + int ret = 1; + asm volatile( + LOCK "subl $1,%0 + js 2f + 1: + .section .text.lock,\"ax\" + 2:" LOCK "inc %0 + subl %1,%1 + jmp 1b + .previous" + :"=m" (*(volatile int *)sem), "=r" (ret) : "1" (ret) : "memory"); + return ret; +} + #endif #endif