On 8/13/06, Dinesh Ahuja <mdlinux7@xxxxxxxxxxx> wrote:
Hi Manish, It is just a macro that expands to a for loop. It is deffined in sched.h #define for_each_process(p) \ for (p = &init_task ; (p = next_task(p)) != &init_task ; ) Right this is a macro. On further investigation, I found that init_task access init_task_union.task {defined in include/asm-i386/processor.h} and next_task is again a macro defined as #define next_task(p) list_entry((p)->tasks.next, struct task_struct, tasks) list_entry is again a macro defined in {include/linux/list.h} as #define list_entry(ptr, type, member) \ ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) In this case, macro uses a init_task_union which is exported by kernel and that should be sufficient for module to iterate over list. But if macro is using an kernel symbol i.e function or a global variable, then these symbols should be exported otherwise use of macro will give unresolved symbols. Please verfiy my understanding.
correct.
I am trying to use read lock before iterating a task list. read_lock(&tasklist_lock); for_each_process(p) { printk ("<1> Iterating Task List" ); } read_unlock(&tasklist_lock); But getting following error: unresolved symbol __read_lock_failed
The tasklist_lock is a rw spinlock. It is again a macro defined in <linux/spinlock.h> regards Manish Regmi -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/