2008-05-20 06:52:27 +07:00
|
|
|
/*
|
2005-04-17 05:20:36 +07:00
|
|
|
* rwsem.h: R/W semaphores implemented using CAS
|
|
|
|
*
|
|
|
|
* Written by David S. Miller (davem@redhat.com), 2001.
|
|
|
|
* Derived from asm-i386/rwsem.h
|
|
|
|
*/
|
|
|
|
#ifndef _SPARC64_RWSEM_H
|
|
|
|
#define _SPARC64_RWSEM_H
|
|
|
|
|
|
|
|
#ifndef _LINUX_RWSEM_H
|
|
|
|
#error "please don't include asm/rwsem.h directly, use linux/rwsem.h instead"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <asm/rwsem-const.h>
|
|
|
|
|
|
|
|
struct rwsem_waiter;
|
|
|
|
|
|
|
|
struct rw_semaphore {
|
|
|
|
signed int count;
|
|
|
|
spinlock_t wait_lock;
|
|
|
|
struct list_head wait_list;
|
2006-11-17 04:38:57 +07:00
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
|
|
struct lockdep_map dep_map;
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2006-11-17 04:38:57 +07:00
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
|
|
# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
|
|
|
|
#else
|
|
|
|
# define __RWSEM_DEP_MAP_INIT(lockname)
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#define __RWSEM_INITIALIZER(name) \
|
2006-11-17 04:38:57 +07:00
|
|
|
{ RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \
|
|
|
|
__RWSEM_DEP_MAP_INIT(name) }
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define DECLARE_RWSEM(name) \
|
|
|
|
struct rw_semaphore name = __RWSEM_INITIALIZER(name)
|
|
|
|
|
2006-11-17 04:38:57 +07:00
|
|
|
extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
|
|
|
|
struct lock_class_key *key);
|
|
|
|
|
|
|
|
#define init_rwsem(sem) \
|
|
|
|
do { \
|
|
|
|
static struct lock_class_key __key; \
|
|
|
|
\
|
|
|
|
__init_rwsem((sem), #sem, &__key); \
|
|
|
|
} while (0)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
extern void __down_read(struct rw_semaphore *sem);
|
|
|
|
extern int __down_read_trylock(struct rw_semaphore *sem);
|
|
|
|
extern void __down_write(struct rw_semaphore *sem);
|
|
|
|
extern int __down_write_trylock(struct rw_semaphore *sem);
|
|
|
|
extern void __up_read(struct rw_semaphore *sem);
|
|
|
|
extern void __up_write(struct rw_semaphore *sem);
|
|
|
|
extern void __downgrade_write(struct rw_semaphore *sem);
|
|
|
|
|
2006-11-17 04:38:57 +07:00
|
|
|
static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
|
|
|
|
{
|
|
|
|
__down_write(sem);
|
|
|
|
}
|
|
|
|
|
2005-07-25 09:35:42 +07:00
|
|
|
static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-07-25 09:35:42 +07:00
|
|
|
return atomic_add_return(delta, (atomic_t *)(&sem->count));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-07-25 09:35:42 +07:00
|
|
|
static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-07-25 09:35:42 +07:00
|
|
|
atomic_add(delta, (atomic_t *)(&sem->count));
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-10-30 08:15:44 +07:00
|
|
|
static inline int rwsem_is_locked(struct rw_semaphore *sem)
|
|
|
|
{
|
|
|
|
return (sem->count != 0);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* _SPARC64_RWSEM_H */
|