Skip to content

Commit 9934ccc

Browse files
Peter Zijlstraingomolnar
authored andcommitted
locking/ww_mutex: Abstract out mutex accessors
Move the mutex related access from various ww_mutex functions into helper functions so they can be substituted for rtmutex based ww_mutex later. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20210815211304.622477030@linutronix.de
1 parent 843dac2 commit 9934ccc

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎kernel/locking/ww_mutex.h‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ __ww_waiter_add(struct mutex *lock, struct mutex_waiter *waiter, struct mutex_wa
5353
__mutex_add_waiter(lock, waiter, p);
5454
}
5555

56+
static inline struct task_struct *
57+
__ww_mutex_owner(struct mutex *lock)
58+
{
59+
return __mutex_owner(lock);
60+
}
61+
62+
static inline bool
63+
__ww_mutex_has_waiters(struct mutex *lock)
64+
{
65+
return atomic_long_read(&lock->owner) & MUTEX_FLAG_WAITERS;
66+
}
67+
5668
/*
5769
* Wait-Die:
5870
* The newer transactions are killed when:
@@ -157,7 +169,7 @@ static bool __ww_mutex_wound(struct mutex *lock,
157169
struct ww_acquire_ctx *ww_ctx,
158170
struct ww_acquire_ctx *hold_ctx)
159171
{
160-
struct task_struct *owner = __mutex_owner(lock);
172+
struct task_struct *owner = __ww_mutex_owner(lock);
161173

162174
lockdep_assert_held(&lock->wait_lock);
163175

@@ -253,7 +265,7 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
253265
* __ww_mutex_add_waiter() and makes sure we either observe ww->ctx
254266
* and/or !empty list.
255267
*/
256-
if (likely(!(atomic_long_read(&lock->base.owner) & MUTEX_FLAG_WAITERS)))
268+
if (likely(!__ww_mutex_has_waiters(&lock->base)))
257269
return;
258270

259271
/*

0 commit comments

Comments
 (0)