aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/pid.h
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@tv-sign.ru>2006-10-02 05:17:22 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-02 10:57:15 -0400
commitd387cae075b0aec479adbdfb71df39f7de8e9adb (patch)
treefe5c9a3b105f3edf4049c16dda4085c5f356fafe /include/linux/pid.h
parentc88be3eb2e01bbb21c9ccdc3805f0d3546c1898c (diff)
[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>
Diffstat (limited to 'include/linux/pid.h')
-rw-r--r--include/linux/pid.h59
1 files changed, 23 insertions, 36 deletions
diff --git a/include/linux/pid.h b/include/linux/pid.h
index dba1b2d677a3..7e39767b4c60 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -102,42 +102,29 @@ static inline pid_t pid_nr(struct pid *pid)
102 return nr; 102 return nr;
103} 103}
104 104
105#define pid_next(task, type) \
106 ((task)->pids[(type)].node.next)
107 105
108#define pid_next_task(task, type) \ 106#define do_each_task_pid(who, type, task) \
109 hlist_entry(pid_next(task, type), struct task_struct, \ 107 do { \
110 pids[(type)].node) 108 struct hlist_node *pos___; \
111 109 struct pid *pid___ = find_pid(who); \
112 110 if (pid___ != NULL) \
113/* We could use hlist_for_each_entry_rcu here but it takes more arguments 111 hlist_for_each_entry_rcu((task), pos___, \
114 * than the do_each_task_pid/while_each_task_pid. So we roll our own 112 &pid___->tasks[type], pids[type].node) {
115 * to preserve the existing interface. 113
116 */ 114#define while_each_task_pid(who, type, task) \
117#define do_each_task_pid(who, type, task) \ 115 } \
118 if ((task = find_task_by_pid_type(type, who))) { \ 116 } while (0)
119 prefetch(pid_next(task, type)); \ 117
120 do { 118
121 119#define do_each_pid_task(pid, type, task) \
122#define while_each_task_pid(who, type, task) \ 120 do { \
123 } while (pid_next(task, type) && ({ \ 121 struct hlist_node *pos___; \
124 task = pid_next_task(task, type); \ 122 if (pid != NULL) \
125 rcu_dereference(task); \ 123 hlist_for_each_entry_rcu((task), pos___, \
126 prefetch(pid_next(task, type)); \ 124 &pid->tasks[type], pids[type].node) {
127 1; }) ); \ 125
128 } 126#define while_each_pid_task(pid, type, task) \
129 127 } \
130#define do_each_pid_task(pid, type, task) \ 128 } while (0)
131 if ((task = pid_task(pid, type))) { \
132 prefetch(pid_next(task, type)); \
133 do {
134
135#define while_each_pid_task(pid, type, task) \
136 } while (pid_next(task, type) && ({ \
137 task = pid_next_task(task, type); \
138 rcu_dereference(task); \
139 prefetch(pid_next(task, type)); \
140 1; }) ); \
141 }
142 129
143#endif /* _LINUX_PID_H */ 130#endif /* _LINUX_PID_H */