提交 843dac28 编写于 作者: P Peter Zijlstra 提交者: Ingo Molnar

locking/ww_mutex: Abstract out waiter enqueueing

The upcoming rtmutex based ww_mutex needs a different handling for
enqueueing a waiter. Split it out into a helper function.
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: NIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20210815211304.566318143@linutronix.de
上级 23d599eb
...@@ -44,6 +44,15 @@ __ww_waiter_last(struct mutex *lock) ...@@ -44,6 +44,15 @@ __ww_waiter_last(struct mutex *lock)
return w; return w;
} }
static inline void
__ww_waiter_add(struct mutex *lock, struct mutex_waiter *waiter, struct mutex_waiter *pos)
{
struct list_head *p = &lock->wait_list;
if (pos)
p = &pos->list;
__mutex_add_waiter(lock, waiter, p);
}
/* /*
* Wait-Die: * Wait-Die:
* The newer transactions are killed when: * The newer transactions are killed when:
...@@ -337,12 +346,11 @@ __ww_mutex_add_waiter(struct mutex_waiter *waiter, ...@@ -337,12 +346,11 @@ __ww_mutex_add_waiter(struct mutex_waiter *waiter,
struct mutex *lock, struct mutex *lock,
struct ww_acquire_ctx *ww_ctx) struct ww_acquire_ctx *ww_ctx)
{ {
struct mutex_waiter *cur; struct mutex_waiter *cur, *pos = NULL;
struct list_head *pos;
bool is_wait_die; bool is_wait_die;
if (!ww_ctx) { if (!ww_ctx) {
__mutex_add_waiter(lock, waiter, &lock->wait_list); __ww_waiter_add(lock, waiter, NULL);
return 0; return 0;
} }
...@@ -355,7 +363,6 @@ __ww_mutex_add_waiter(struct mutex_waiter *waiter, ...@@ -355,7 +363,6 @@ __ww_mutex_add_waiter(struct mutex_waiter *waiter,
* never die here, but they are sorted in stamp order and * never die here, but they are sorted in stamp order and
* may wound the lock holder. * may wound the lock holder.
*/ */
pos = &lock->wait_list;
for (cur = __ww_waiter_last(lock); cur; for (cur = __ww_waiter_last(lock); cur;
cur = __ww_waiter_prev(lock, cur)) { cur = __ww_waiter_prev(lock, cur)) {
...@@ -378,13 +385,13 @@ __ww_mutex_add_waiter(struct mutex_waiter *waiter, ...@@ -378,13 +385,13 @@ __ww_mutex_add_waiter(struct mutex_waiter *waiter,
break; break;
} }
pos = &cur->list; pos = cur;
/* Wait-Die: ensure younger waiters die. */ /* Wait-Die: ensure younger waiters die. */
__ww_mutex_die(lock, cur, ww_ctx); __ww_mutex_die(lock, cur, ww_ctx);
} }
__mutex_add_waiter(lock, waiter, pos); __ww_waiter_add(lock, waiter, pos);
/* /*
* Wound-Wait: if we're blocking on a mutex owned by a younger context, * Wound-Wait: if we're blocking on a mutex owned by a younger context,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册