Skip to content

Commit

Permalink
locking/rwsem: Rename 'activity' to 'count'
Browse files Browse the repository at this point in the history
There are two definitions of struct rw_semaphore, one in linux/rwsem.h
and one in linux/rwsem-spinlock.h.

For some reason they have different names for the initial field. This
makes it impossible to use C99 named initialization for
__RWSEM_INITIALIZER() -- or we have to duplicate that entire thing
along with the structure definitions.

The simpler patch is renaming the rwsem-spinlock variant to match the
regular rwsem.

This allows us to switch to C99 named initialization.

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/n/tip-bmrZolsbGmautmzrerog27io@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Jul 16, 2014
1 parent 33ecd20 commit 13b9a96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions include/linux/rwsem-spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#ifdef __KERNEL__
/*
* the rw-semaphore definition
* - if activity is 0 then there are no active readers or writers
* - if activity is +ve then that is the number of active readers
* - if activity is -1 then there is one active writer
* - if count is 0 then there are no active readers or writers
* - if count is +ve then that is the number of active readers
* - if count is -1 then there is one active writer
* - if wait_list is not empty, then there are processes waiting for the semaphore
*/
struct rw_semaphore {
__s32 activity;
__s32 count;
raw_spinlock_t wait_lock;
struct list_head wait_list;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
Expand Down
28 changes: 14 additions & 14 deletions kernel/locking/rwsem-spinlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int rwsem_is_locked(struct rw_semaphore *sem)
unsigned long flags;

if (raw_spin_trylock_irqsave(&sem->wait_lock, flags)) {
ret = (sem->activity != 0);
ret = (sem->count != 0);
raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
}
return ret;
Expand All @@ -46,7 +46,7 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name,
debug_check_no_locks_freed((void *)sem, sizeof(*sem));
lockdep_init_map(&sem->dep_map, name, key, 0);
#endif
sem->activity = 0;
sem->count = 0;
raw_spin_lock_init(&sem->wait_lock);
INIT_LIST_HEAD(&sem->wait_list);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ __rwsem_do_wake(struct rw_semaphore *sem, int wakewrite)
waiter = list_entry(next, struct rwsem_waiter, list);
} while (waiter->type != RWSEM_WAITING_FOR_WRITE);

sem->activity += woken;
sem->count += woken;

out:
return sem;
Expand Down Expand Up @@ -126,9 +126,9 @@ void __sched __down_read(struct rw_semaphore *sem)

raw_spin_lock_irqsave(&sem->wait_lock, flags);

if (sem->activity >= 0 && list_empty(&sem->wait_list)) {
if (sem->count >= 0 && list_empty(&sem->wait_list)) {
/* granted */
sem->activity++;
sem->count++;
raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
goto out;
}
Expand Down Expand Up @@ -170,9 +170,9 @@ int __down_read_trylock(struct rw_semaphore *sem)

raw_spin_lock_irqsave(&sem->wait_lock, flags);

if (sem->activity >= 0 && list_empty(&sem->wait_list)) {
if (sem->count >= 0 && list_empty(&sem->wait_list)) {
/* granted */
sem->activity++;
sem->count++;
ret = 1;
}

Expand Down Expand Up @@ -206,15 +206,15 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
* itself into sleep and waiting for system woke it or someone
* else in the head of the wait list up.
*/
if (sem->activity == 0)
if (sem->count == 0)
break;
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
schedule();
raw_spin_lock_irqsave(&sem->wait_lock, flags);
}
/* got the lock */
sem->activity = -1;
sem->count = -1;
list_del(&waiter.list);

raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
Expand All @@ -235,9 +235,9 @@ int __down_write_trylock(struct rw_semaphore *sem)

raw_spin_lock_irqsave(&sem->wait_lock, flags);

if (sem->activity == 0) {
if (sem->count == 0) {
/* got the lock */
sem->activity = -1;
sem->count = -1;
ret = 1;
}

Expand All @@ -255,7 +255,7 @@ void __up_read(struct rw_semaphore *sem)

raw_spin_lock_irqsave(&sem->wait_lock, flags);

if (--sem->activity == 0 && !list_empty(&sem->wait_list))
if (--sem->count == 0 && !list_empty(&sem->wait_list))
sem = __rwsem_wake_one_writer(sem);

raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
Expand All @@ -270,7 +270,7 @@ void __up_write(struct rw_semaphore *sem)

raw_spin_lock_irqsave(&sem->wait_lock, flags);

sem->activity = 0;
sem->count = 0;
if (!list_empty(&sem->wait_list))
sem = __rwsem_do_wake(sem, 1);

Expand All @@ -287,7 +287,7 @@ void __downgrade_write(struct rw_semaphore *sem)

raw_spin_lock_irqsave(&sem->wait_lock, flags);

sem->activity = 1;
sem->count = 1;
if (!list_empty(&sem->wait_list))
sem = __rwsem_do_wake(sem, 0);

Expand Down

0 comments on commit 13b9a96

Please sign in to comment.