lkml.org 
[lkml]   [2013]   [Mar]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5 39/44] tty: Factor ldsem writer trylock
Date
Prepare to simplify lock acquistion by waiting writer.

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

Cc: Michel Lespinasse <walken@google.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
---
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


\
 
 \ /
  Last update: 2013-03-12 05:02    [W:1.402 / U:0.180 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site