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
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"
16 #include <linux/list.h>
17 #include <linux/spinlock.h>
18 #include <asm/rwsem-const.h>
25 struct list_head wait_list
;
26 #ifdef CONFIG_DEBUG_LOCK_ALLOC
27 struct lockdep_map dep_map
;
31 #ifdef CONFIG_DEBUG_LOCK_ALLOC
32 # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
34 # define __RWSEM_DEP_MAP_INIT(lockname)
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) \
49 static struct lock_class_key __key; \
51 __init_rwsem((sem), #sem, &__key); \
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
)
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 */