Skip to content

Commit

Permalink
[PATCH] lockdep: clean up rwsems
Browse files Browse the repository at this point in the history
Clean up rwsems.

Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ingo Molnar authored and Linus Torvalds committed Jul 3, 2006
1 parent 8b3db9c commit c4e0511
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 128 deletions.
17 changes: 1 addition & 16 deletions include/asm-i386/rwsem.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,11 @@ struct rw_semaphore {
#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
spinlock_t wait_lock;
struct list_head wait_list;
#if RWSEM_DEBUG
int debug;
#endif
};

/*
* initialisation
*/
#if RWSEM_DEBUG
#define __RWSEM_DEBUG_INIT , 0
#else
#define __RWSEM_DEBUG_INIT /* */
#endif

#define __RWSEM_INITIALIZER(name) \
{ RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \
__RWSEM_DEBUG_INIT }
}

#define DECLARE_RWSEM(name) \
struct rw_semaphore name = __RWSEM_INITIALIZER(name)
Expand All @@ -87,9 +75,6 @@ static inline void init_rwsem(struct rw_semaphore *sem)
sem->count = RWSEM_UNLOCKED_VALUE;
spin_lock_init(&sem->wait_lock);
INIT_LIST_HEAD(&sem->wait_list);
#if RWSEM_DEBUG
sem->debug = 0;
#endif
}

/*
Expand Down
14 changes: 1 addition & 13 deletions include/linux/rwsem-spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,10 @@ struct rw_semaphore {
__s32 activity;
spinlock_t wait_lock;
struct list_head wait_list;
#if RWSEM_DEBUG
int debug;
#endif
};

/*
* initialisation
*/
#if RWSEM_DEBUG
#define __RWSEM_DEBUG_INIT , 0
#else
#define __RWSEM_DEBUG_INIT /* */
#endif

#define __RWSEM_INITIALIZER(name) \
{ 0, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) __RWSEM_DEBUG_INIT }
{ 0, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) }

#define DECLARE_RWSEM(name) \
struct rw_semaphore name = __RWSEM_INITIALIZER(name)
Expand Down
24 changes: 0 additions & 24 deletions include/linux/rwsem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include <linux/linkage.h>

#define RWSEM_DEBUG 0

#ifdef __KERNEL__

#include <linux/types.h>
Expand All @@ -26,23 +24,13 @@ struct rw_semaphore;
#include <asm/rwsem.h> /* use an arch-specific implementation */
#endif

#ifndef rwsemtrace
#if RWSEM_DEBUG
extern void FASTCALL(rwsemtrace(struct rw_semaphore *sem, const char *str));
#else
#define rwsemtrace(SEM,FMT)
#endif
#endif

/*
* lock for reading
*/
static inline void down_read(struct rw_semaphore *sem)
{
might_sleep();
rwsemtrace(sem,"Entering down_read");
__down_read(sem);
rwsemtrace(sem,"Leaving down_read");
}

/*
Expand All @@ -51,9 +39,7 @@ static inline void down_read(struct rw_semaphore *sem)
static inline int down_read_trylock(struct rw_semaphore *sem)
{
int ret;
rwsemtrace(sem,"Entering down_read_trylock");
ret = __down_read_trylock(sem);
rwsemtrace(sem,"Leaving down_read_trylock");
return ret;
}

Expand All @@ -63,9 +49,7 @@ static inline int down_read_trylock(struct rw_semaphore *sem)
static inline void down_write(struct rw_semaphore *sem)
{
might_sleep();
rwsemtrace(sem,"Entering down_write");
__down_write(sem);
rwsemtrace(sem,"Leaving down_write");
}

/*
Expand All @@ -74,9 +58,7 @@ static inline void down_write(struct rw_semaphore *sem)
static inline int down_write_trylock(struct rw_semaphore *sem)
{
int ret;
rwsemtrace(sem,"Entering down_write_trylock");
ret = __down_write_trylock(sem);
rwsemtrace(sem,"Leaving down_write_trylock");
return ret;
}

Expand All @@ -85,29 +67,23 @@ static inline int down_write_trylock(struct rw_semaphore *sem)
*/
static inline void up_read(struct rw_semaphore *sem)
{
rwsemtrace(sem,"Entering up_read");
__up_read(sem);
rwsemtrace(sem,"Leaving up_read");
}

/*
* release a write lock
*/
static inline void up_write(struct rw_semaphore *sem)
{
rwsemtrace(sem,"Entering up_write");
__up_write(sem);
rwsemtrace(sem,"Leaving up_write");
}

/*
* downgrade write lock to read lock
*/
static inline void downgrade_write(struct rw_semaphore *sem)
{
rwsemtrace(sem,"Entering downgrade_write");
__downgrade_write(sem);
rwsemtrace(sem,"Leaving downgrade_write");
}

#endif /* __KERNEL__ */
Expand Down
105 changes: 105 additions & 0 deletions kernel/rwsem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* kernel/rwsem.c: R/W semaphores, public implementation
*
* Written by David Howells ([email protected]).
* Derived from asm-i386/semaphore.h
*/

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rwsem.h>

#include <asm/system.h>
#include <asm/atomic.h>

/*
* lock for reading
*/
void down_read(struct rw_semaphore *sem)
{
might_sleep();
rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);

__down_read(sem);
}

EXPORT_SYMBOL(down_read);

/*
* trylock for reading -- returns 1 if successful, 0 if contention
*/
int down_read_trylock(struct rw_semaphore *sem)
{
int ret = __down_read_trylock(sem);

if (ret == 1)
rwsem_acquire_read(&sem->dep_map, 0, 1, _RET_IP_);
return ret;
}

EXPORT_SYMBOL(down_read_trylock);

/*
* lock for writing
*/
void down_write(struct rw_semaphore *sem)
{
might_sleep();
rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);

__down_write(sem);
}

EXPORT_SYMBOL(down_write);

/*
* trylock for writing -- returns 1 if successful, 0 if contention
*/
int down_write_trylock(struct rw_semaphore *sem)
{
int ret = __down_write_trylock(sem);

if (ret == 1)
rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
return ret;
}

EXPORT_SYMBOL(down_write_trylock);

/*
* release a read lock
*/
void up_read(struct rw_semaphore *sem)
{
rwsem_release(&sem->dep_map, 1, _RET_IP_);

__up_read(sem);
}

EXPORT_SYMBOL(up_read);

/*
* release a write lock
*/
void up_write(struct rw_semaphore *sem)
{
rwsem_release(&sem->dep_map, 1, _RET_IP_);

__up_write(sem);
}

EXPORT_SYMBOL(up_write);

/*
* downgrade write lock to read lock
*/
void downgrade_write(struct rw_semaphore *sem)
{
/*
* lockdep: a downgraded write will live on as a write
* dependency.
*/
__downgrade_write(sem);
}

EXPORT_SYMBOL(downgrade_write);
Loading

0 comments on commit c4e0511

Please sign in to comment.