Skip to content

Commit 50816c4

Browse files
author
Ingo Molnar
committed
sched/wait: Standardize internal naming of wait-queue entries
So the various wait-queue entry variables in include/linux/wait.h and kernel/sched/wait.c are named in a colorfully inconsistent way: wait_queue_entry_t *wait wait_queue_entry_t *__wait (even in plain C code!) wait_queue_entry_t *q (!) wait_queue_entry_t *new (making anyone who knows C++ cringe) wait_queue_entry_t *old I think part of the reason for the inconsistency is the constant apparent confusion about what a wait queue 'head' versus 'entry' is. ( Some of the documentation talks about a 'wait descriptor', which is the wait-queue entry itself - further adding to the confusion. ) The most common name is 'wait', but that in itself is somewhat ambiguous as well, as it does not really make it clear whether it's a wait-queue entry or head. To improve all this name the wait-queue entry structure parameters and variables consistently and push through this naming into all the wait.h and wait.c code: struct wait_queue_entry *wq_entry The 'wq_' prefix makes it easy to grep for, and we also use the opportunity to move away from the typedef to a plain 'struct' naming: in the kernel we typically reserve typedefs for cases where a C structure is really small and somewhat opaque - such as pte_t. wait-queue entries are neither small nor opaque, so use the more standard 'struct xxx_entry' list management code nomenclature instead. ( We don't touch external users, and we preserve the typedef as well for actual wait-queue users, to reduce unnecessary churn. ) Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent ac6424b commit 50816c4

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

include/linux/wait.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#include <uapi/linux/wait.h>
1212

1313
typedef struct wait_queue_entry wait_queue_entry_t;
14-
typedef int (*wait_queue_func_t)(wait_queue_entry_t *wait, unsigned mode, int flags, void *key);
15-
int default_wake_function(wait_queue_entry_t *wait, unsigned mode, int flags, void *key);
14+
15+
typedef int (*wait_queue_func_t)(struct wait_queue_entry *wq_entry, unsigned mode, int flags, void *key);
16+
int default_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int flags, void *key);
1617

1718
/* wait_queue_entry::flags */
1819
#define WQ_FLAG_EXCLUSIVE 0x01
@@ -37,7 +38,7 @@ struct wait_bit_key {
3738

3839
struct wait_bit_queue {
3940
struct wait_bit_key key;
40-
wait_queue_entry_t wait;
41+
struct wait_queue_entry wait;
4142
};
4243

4344
struct __wait_queue_head {
@@ -58,7 +59,7 @@ struct task_struct;
5859
.task_list = { NULL, NULL } }
5960

6061
#define DECLARE_WAITQUEUE(name, tsk) \
61-
wait_queue_entry_t name = __WAITQUEUE_INITIALIZER(name, tsk)
62+
struct wait_queue_entry name = __WAITQUEUE_INITIALIZER(name, tsk)
6263

6364
#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
6465
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \
@@ -91,19 +92,19 @@ extern void __init_waitqueue_head(wait_queue_head_t *q, const char *name, struct
9192
# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
9293
#endif
9394

94-
static inline void init_waitqueue_entry(wait_queue_entry_t *q, struct task_struct *p)
95+
static inline void init_waitqueue_entry(struct wait_queue_entry *wq_entry, struct task_struct *p)
9596
{
96-
q->flags = 0;
97-
q->private = p;
98-
q->func = default_wake_function;
97+
wq_entry->flags = 0;
98+
wq_entry->private = p;
99+
wq_entry->func = default_wake_function;
99100
}
100101

101102
static inline void
102-
init_waitqueue_func_entry(wait_queue_entry_t *q, wait_queue_func_t func)
103+
init_waitqueue_func_entry(struct wait_queue_entry *wq_entry, wait_queue_func_t func)
103104
{
104-
q->flags = 0;
105-
q->private = NULL;
106-
q->func = func;
105+
wq_entry->flags = 0;
106+
wq_entry->private = NULL;
107+
wq_entry->func = func;
107108
}
108109

109110
/**
@@ -162,42 +163,41 @@ static inline bool wq_has_sleeper(wait_queue_head_t *wq)
162163
return waitqueue_active(wq);
163164
}
164165

165-
extern void add_wait_queue(wait_queue_head_t *q, wait_queue_entry_t *wait);
166-
extern void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_entry_t *wait);
167-
extern void remove_wait_queue(wait_queue_head_t *q, wait_queue_entry_t *wait);
166+
extern void add_wait_queue(wait_queue_head_t *q, struct wait_queue_entry *wq_entry);
167+
extern void add_wait_queue_exclusive(wait_queue_head_t *q, struct wait_queue_entry *wq_entry);
168+
extern void remove_wait_queue(wait_queue_head_t *q, struct wait_queue_entry *wq_entry);
168169

169-
static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *new)
170+
static inline void __add_wait_queue(wait_queue_head_t *head, struct wait_queue_entry *wq_entry)
170171
{
171-
list_add(&new->task_list, &head->task_list);
172+
list_add(&wq_entry->task_list, &head->task_list);
172173
}
173174

174175
/*
175176
* Used for wake-one threads:
176177
*/
177178
static inline void
178-
__add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_entry_t *wait)
179+
__add_wait_queue_exclusive(wait_queue_head_t *q, struct wait_queue_entry *wq_entry)
179180
{
180-
wait->flags |= WQ_FLAG_EXCLUSIVE;
181-
__add_wait_queue(q, wait);
181+
wq_entry->flags |= WQ_FLAG_EXCLUSIVE;
182+
__add_wait_queue(q, wq_entry);
182183
}
183184

184-
static inline void __add_wait_queue_entry_tail(wait_queue_head_t *head,
185-
wait_queue_entry_t *new)
185+
static inline void __add_wait_queue_entry_tail(wait_queue_head_t *head, struct wait_queue_entry *wq_entry)
186186
{
187-
list_add_tail(&new->task_list, &head->task_list);
187+
list_add_tail(&wq_entry->task_list, &head->task_list);
188188
}
189189

190190
static inline void
191-
__add_wait_queue_entry_tail_exclusive(wait_queue_head_t *q, wait_queue_entry_t *wait)
191+
__add_wait_queue_entry_tail_exclusive(wait_queue_head_t *q, struct wait_queue_entry *wq_entry)
192192
{
193-
wait->flags |= WQ_FLAG_EXCLUSIVE;
194-
__add_wait_queue_entry_tail(q, wait);
193+
wq_entry->flags |= WQ_FLAG_EXCLUSIVE;
194+
__add_wait_queue_entry_tail(q, wq_entry);
195195
}
196196

197197
static inline void
198-
__remove_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *old)
198+
__remove_wait_queue(wait_queue_head_t *head, struct wait_queue_entry *wq_entry)
199199
{
200-
list_del(&old->task_list);
200+
list_del(&wq_entry->task_list);
201201
}
202202

203203
typedef int wait_bit_action_f(struct wait_bit_key *, int mode);
@@ -252,7 +252,7 @@ wait_queue_head_t *bit_waitqueue(void *, int);
252252
(!__builtin_constant_p(state) || \
253253
state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE) \
254254

255-
extern void init_wait_entry(wait_queue_entry_t *__wait, int flags);
255+
extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
256256

257257
/*
258258
* The below macro ___wait_event() has an explicit shadow of the __ret
@@ -269,12 +269,12 @@ extern void init_wait_entry(wait_queue_entry_t *__wait, int flags);
269269
#define ___wait_event(wq, condition, state, exclusive, ret, cmd) \
270270
({ \
271271
__label__ __out; \
272-
wait_queue_entry_t __wait; \
272+
struct wait_queue_entry __wq_entry; \
273273
long __ret = ret; /* explicit shadow */ \
274274
\
275-
init_wait_entry(&__wait, exclusive ? WQ_FLAG_EXCLUSIVE : 0); \
275+
init_wait_entry(&__wq_entry, exclusive ? WQ_FLAG_EXCLUSIVE : 0);\
276276
for (;;) { \
277-
long __int = prepare_to_wait_event(&wq, &__wait, state);\
277+
long __int = prepare_to_wait_event(&wq, &__wq_entry, state);\
278278
\
279279
if (condition) \
280280
break; \
@@ -286,7 +286,7 @@ extern void init_wait_entry(wait_queue_entry_t *__wait, int flags);
286286
\
287287
cmd; \
288288
} \
289-
finish_wait(&wq, &__wait); \
289+
finish_wait(&wq, &__wq_entry); \
290290
__out: __ret; \
291291
})
292292

@@ -970,17 +970,17 @@ do { \
970970
/*
971971
* Waitqueues which are removed from the waitqueue_head at wakeup time
972972
*/
973-
void prepare_to_wait(wait_queue_head_t *q, wait_queue_entry_t *wait, int state);
974-
void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_entry_t *wait, int state);
975-
long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_entry_t *wait, int state);
976-
void finish_wait(wait_queue_head_t *q, wait_queue_entry_t *wait);
977-
long wait_woken(wait_queue_entry_t *wait, unsigned mode, long timeout);
978-
int woken_wake_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *key);
979-
int autoremove_wake_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *key);
980-
int wake_bit_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *key);
973+
void prepare_to_wait(wait_queue_head_t *q, struct wait_queue_entry *wq_entry, int state);
974+
void prepare_to_wait_exclusive(wait_queue_head_t *q, struct wait_queue_entry *wq_entry, int state);
975+
long prepare_to_wait_event(wait_queue_head_t *q, struct wait_queue_entry *wq_entry, int state);
976+
void finish_wait(wait_queue_head_t *q, struct wait_queue_entry *wq_entry);
977+
long wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout);
978+
int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
979+
int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
980+
int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
981981

982982
#define DEFINE_WAIT_FUNC(name, function) \
983-
wait_queue_entry_t name = { \
983+
struct wait_queue_entry name = { \
984984
.private = current, \
985985
.func = function, \
986986
.task_list = LIST_HEAD_INIT((name).task_list), \

0 commit comments

Comments
 (0)