Skip to content

Commit e52c434

Browse files
committed
futex: abstract out a __futex_wake_mark() helper
Move the unqueue and lock_ptr clear into a helper that futex_wake_mark() calls. Add it to the public functions as well, in preparation for using it outside the core futex code. Suggested-by: Peter Zijlstra <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 12a4be5 commit e52c434

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

kernel/futex/futex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ extern int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
219219
struct futex_q *q, struct futex_hash_bucket **hb);
220220
extern void futex_wait_queue(struct futex_hash_bucket *hb, struct futex_q *q,
221221
struct hrtimer_sleeper *timeout);
222+
extern bool __futex_wake_mark(struct futex_q *q);
222223
extern void futex_wake_mark(struct wake_q_head *wake_q, struct futex_q *q);
223224

224225
extern int fault_in_user_writeable(u32 __user *uaddr);

kernel/futex/waitwake.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,11 @@
106106
* double_lock_hb() and double_unlock_hb(), respectively.
107107
*/
108108

109-
/*
110-
* The hash bucket lock must be held when this is called.
111-
* Afterwards, the futex_q must not be accessed. Callers
112-
* must ensure to later call wake_up_q() for the actual
113-
* wakeups to occur.
114-
*/
115-
void futex_wake_mark(struct wake_q_head *wake_q, struct futex_q *q)
109+
bool __futex_wake_mark(struct futex_q *q)
116110
{
117-
struct task_struct *p = q->task;
118-
119111
if (WARN(q->pi_state || q->rt_waiter, "refusing to wake PI futex\n"))
120-
return;
112+
return false;
121113

122-
get_task_struct(p);
123114
__futex_unqueue(q);
124115
/*
125116
* The waiting task can free the futex_q as soon as q->lock_ptr = NULL
@@ -130,6 +121,26 @@ void futex_wake_mark(struct wake_q_head *wake_q, struct futex_q *q)
130121
*/
131122
smp_store_release(&q->lock_ptr, NULL);
132123

124+
return true;
125+
}
126+
127+
/*
128+
* The hash bucket lock must be held when this is called.
129+
* Afterwards, the futex_q must not be accessed. Callers
130+
* must ensure to later call wake_up_q() for the actual
131+
* wakeups to occur.
132+
*/
133+
void futex_wake_mark(struct wake_q_head *wake_q, struct futex_q *q)
134+
{
135+
struct task_struct *p = q->task;
136+
137+
get_task_struct(p);
138+
139+
if (!__futex_wake_mark(q)) {
140+
put_task_struct(p);
141+
return;
142+
}
143+
133144
/*
134145
* Queue the task for later wakeup for after we've released
135146
* the hb->lock.

0 commit comments

Comments
 (0)