Index: include/asm-i386/rwsem.h =================================================================== RCS file: /src/nsc_linux/src/kernel/include/asm-i386/rwsem.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 rwsem.h --- include/asm-i386/rwsem.h 2001/04/27 22:48:24 1.1.1.1 +++ include/asm-i386/rwsem.h 2001/07/06 20:54:13 @@ -222,5 +222,34 @@ return tmp+delta; } +#if __HAVE_ARCH_CMPXCHG +/* returns 1 if it successfully obtained the semaphore for write */ +static inline int down_write_trylock(struct rw_semaphore *sem) +{ + signed long ret = cmpxchg(&sem->count, + RWSEM_UNLOCKED_VALUE, + RWSEM_ACTIVE_WRITE_BIAS); + if (ret == RWSEM_UNLOCKED_VALUE) + return 1; + return 0; +} + +/* returns 1 if it successfully obtained the semaphore for read */ +static inline int down_read_trylock(struct rw_semaphore *sem) +{ + signed long old, new; + +repeat: + old = (volatile signed long)sem->count; + if (old < RWSEM_UNLOCKED_VALUE) + return 0; + new = old + RWSEM_ACTIVE_READ_BIAS; + if (cmpxchg(&sem->count, old, new) == old) + return 1; + else + goto repeat; +} +#endif /* __HAVE_ARCH_CMPXCHG */ + #endif /* __KERNEL__ */ #endif /* _I386_RWSEM_H */