[PATCH] pid: simplify pid iterators
I think it is hardly possible to read the current do_each_task_pid(). The new version is much simpler and makes the code smaller. Only the do_each_task_pid change is tested, the do_each_pid_task isn't. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
c88be3eb2e
commit
d387cae075
|
@ -102,42 +102,29 @@ static inline pid_t pid_nr(struct pid *pid)
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define pid_next(task, type) \
|
|
||||||
((task)->pids[(type)].node.next)
|
|
||||||
|
|
||||||
#define pid_next_task(task, type) \
|
#define do_each_task_pid(who, type, task) \
|
||||||
hlist_entry(pid_next(task, type), struct task_struct, \
|
do { \
|
||||||
pids[(type)].node)
|
struct hlist_node *pos___; \
|
||||||
|
struct pid *pid___ = find_pid(who); \
|
||||||
|
if (pid___ != NULL) \
|
||||||
|
hlist_for_each_entry_rcu((task), pos___, \
|
||||||
|
&pid___->tasks[type], pids[type].node) {
|
||||||
|
|
||||||
|
#define while_each_task_pid(who, type, task) \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/* We could use hlist_for_each_entry_rcu here but it takes more arguments
|
#define do_each_pid_task(pid, type, task) \
|
||||||
* than the do_each_task_pid/while_each_task_pid. So we roll our own
|
do { \
|
||||||
* to preserve the existing interface.
|
struct hlist_node *pos___; \
|
||||||
*/
|
if (pid != NULL) \
|
||||||
#define do_each_task_pid(who, type, task) \
|
hlist_for_each_entry_rcu((task), pos___, \
|
||||||
if ((task = find_task_by_pid_type(type, who))) { \
|
&pid->tasks[type], pids[type].node) {
|
||||||
prefetch(pid_next(task, type)); \
|
|
||||||
do {
|
|
||||||
|
|
||||||
#define while_each_task_pid(who, type, task) \
|
#define while_each_pid_task(pid, type, task) \
|
||||||
} while (pid_next(task, type) && ({ \
|
} \
|
||||||
task = pid_next_task(task, type); \
|
} while (0)
|
||||||
rcu_dereference(task); \
|
|
||||||
prefetch(pid_next(task, type)); \
|
|
||||||
1; }) ); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define do_each_pid_task(pid, type, task) \
|
|
||||||
if ((task = pid_task(pid, type))) { \
|
|
||||||
prefetch(pid_next(task, type)); \
|
|
||||||
do {
|
|
||||||
|
|
||||||
#define while_each_pid_task(pid, type, task) \
|
|
||||||
} while (pid_next(task, type) && ({ \
|
|
||||||
task = pid_next_task(task, type); \
|
|
||||||
rcu_dereference(task); \
|
|
||||||
prefetch(pid_next(task, type)); \
|
|
||||||
1; }) ); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _LINUX_PID_H */
|
#endif /* _LINUX_PID_H */
|
||||||
|
|
Loading…
Reference in a new issue