[PATCH v5 39/44] tty: Factor ldsem writer trylock

From: Peter Hurley
Date: Mon Mar 11 2013 - 17:19:39 EST


Prepare to simplify lock acquistion by waiting writer.

Derived from Michel Lespinasse's write lock stealing work on rwsem.

Cc: Michel Lespinasse <walken@xxxxxxxxxx>
Signed-off-by: Peter Hurley <peter@xxxxxxxxxxxxxxxxxx>
---
drivers/tty/tty_ldsem.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c
index d2f091a..48f1ce8 100644
--- a/drivers/tty/tty_ldsem.c
+++ b/drivers/tty/tty_ldsem.c
@@ -136,13 +136,8 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem)
sem->wait_readers = 0;
}

-static void __ldsem_wake_writer(struct ld_semaphore *sem)
+static inline int writer_trylock(struct ld_semaphore *sem)
{
- struct ldsem_waiter *waiter;
- struct task_struct *tsk;
-
- waiter = list_entry(sem->write_wait.next, struct ldsem_waiter, list);
-
/* only wake this writer if the active part of the count can be
* transitioned from 0 -> 1
*/
@@ -159,9 +154,22 @@ static void __ldsem_wake_writer(struct ld_semaphore *sem)
*/
count = ldsem_atomic_update(-LDSEM_ACTIVE_BIAS, sem);
if (count & LDSEM_ACTIVE_MASK)
- return;
+ return 0;
} while (1);

+ return 1;
+}
+
+static void __ldsem_wake_writer(struct ld_semaphore *sem)
+{
+ struct ldsem_waiter *waiter;
+ struct task_struct *tsk;
+
+ waiter = list_entry(sem->write_wait.next, struct ldsem_waiter, list);
+
+ if (!writer_trylock(sem))
+ return;
+
/* We must be careful not to touch 'waiter' after we set ->task = NULL.
* It is an allocated on the waiter's stack and may become invalid at
* any time after that point (due to a wakeup from another source).
--
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/