[RFC, PATCH] introduce pid_for_each_task() to replacedo_each_pid_task()

From: Oleg Nesterov
Date: Tue Feb 24 2009 - 16:52:45 EST


pid_for_each_task() does the same as
do_each_pid_task() + while_each_pid_task(), so instead of

do_each_pid_task(pid, type, task) {
do_something(task);
} while_each_pid_task(pid, type, task);

we can just do

pid_for_each_task(pid, type, task)
do_something(task);

This looks better, and we can use break/continue safely.

This patch changes do_each_pid_task() to use pid_for_each_task(), once
we convert all users of do_each_pid_task() we can kill this helper.

However. The implementation of pid_for_each_task() itself is anything
but clean/simple, so this patch asks for the explicit acks/nacks.

Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>

--- 6.29-rc3/include/linux/pid.h~FOR_EACH_PID 2009-01-12 23:07:48.000000000 +0100
+++ 6.29-rc3/include/linux/pid.h 2009-02-24 22:07:48.000000000 +0100
@@ -162,21 +162,25 @@ static inline pid_t pid_nr(struct pid *p
pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
pid_t pid_vnr(struct pid *pid);

+/*
+ * Both old and new leaders may be attached to the same pid in the
+ * middle of de_thread(), that is why we do the special check for
+ * PIDTYPE_PID below.
+ */
+#define pid_for_each_task(pid, type, p) \
+ for (p = (pid) ? (void*)(pid)->tasks[type].first : NULL; \
+ rcu_dereference(p) && ({ \
+ prefetch(((struct hlist_node*)p)->next); \
+ p = hlist_entry((void*)p, typeof(*p), pids[type].node); \
+ 1; }); \
+ p = ((type) != PIDTYPE_PID) ? \
+ (void*)(p)->pids[type].node.next : NULL)
+
#define do_each_pid_task(pid, type, task) \
do { \
- struct hlist_node *pos___; \
- if ((pid) != NULL) \
- hlist_for_each_entry_rcu((task), pos___, \
- &(pid)->tasks[type], pids[type].node) {
+ pid_for_each_task(pid, type, task)

- /*
- * Both old and new leaders may be attached to
- * the same pid in the middle of de_thread().
- */
#define while_each_pid_task(pid, type, task) \
- if (type == PIDTYPE_PID) \
- break; \
- } \
} while (0)

#define do_each_pid_thread(pid, type, task) \

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/