[PARISC] Move #undef to end of syscall table
[linux-2.6.git] / include / asm-sparc64 / rwsem.h
blob1294b7ce5d06c0987870424ddfceacc87ed42b08
1 /* $Id: rwsem.h,v 1.5 2001/11/18 00:12:56 davem Exp $
2 * rwsem.h: R/W semaphores implemented using CAS
4 * Written by David S. Miller (davem@redhat.com), 2001.
5 * Derived from asm-i386/rwsem.h
6 */
7 #ifndef _SPARC64_RWSEM_H
8 #define _SPARC64_RWSEM_H
10 #ifndef _LINUX_RWSEM_H
11 #error "please don't include asm/rwsem.h directly, use linux/rwsem.h instead"
12 #endif
14 #ifdef __KERNEL__
16 #include <linux/list.h>
17 #include <linux/spinlock.h>
18 #include <asm/rwsem-const.h>
20 struct rwsem_waiter;
22 struct rw_semaphore {
23 signed int count;
24 spinlock_t wait_lock;
25 struct list_head wait_list;
26 #ifdef CONFIG_DEBUG_LOCK_ALLOC
27 struct lockdep_map dep_map;
28 #endif
31 #ifdef CONFIG_DEBUG_LOCK_ALLOC
32 # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
33 #else
34 # define __RWSEM_DEP_MAP_INIT(lockname)
35 #endif
37 #define __RWSEM_INITIALIZER(name) \
38 { RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \
39 __RWSEM_DEP_MAP_INIT(name) }
41 #define DECLARE_RWSEM(name) \
42 struct rw_semaphore name = __RWSEM_INITIALIZER(name)
44 extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
45 struct lock_class_key *key);
47 #define init_rwsem(sem) \
48 do { \
49 static struct lock_class_key __key; \
51 __init_rwsem((sem), #sem, &__key); \
52 } while (0)
54 extern void __down_read(struct rw_semaphore *sem);
55 extern int __down_read_trylock(struct rw_semaphore *sem);
56 extern void __down_write(struct rw_semaphore *sem);
57 extern int __down_write_trylock(struct rw_semaphore *sem);
58 extern void __up_read(struct rw_semaphore *sem);
59 extern void __up_write(struct rw_semaphore *sem);
60 extern void __downgrade_write(struct rw_semaphore *sem);
62 static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
64 __down_write(sem);
67 static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
69 return atomic_add_return(delta, (atomic_t *)(&sem->count));
72 static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
74 atomic_add(delta, (atomic_t *)(&sem->count));
77 static inline int rwsem_is_locked(struct rw_semaphore *sem)
79 return (sem->count != 0);
82 #endif /* __KERNEL__ */
84 #endif /* _SPARC64_RWSEM_H */