android binder驱动程序实现

时间:2018-04-13 09:06:42

标签: android linux-device-driver android-binder

我正在学习活页夹驱动程序。它有一个结构sed '2,3{s/$/ 0 0 0/}' file 用于保存线程信息。我发现它使用binder_thread分配的binder_thread.pid来区分彼此。例如,在current->pid方法中,该字段用于判断当前线程是否已添加到树中。

binder_get_thread

但据我所知,static struct binder_thread *binder_get_thread(struct binder_proc *proc) { struct binder_thread *thread = NULL; struct rb_node *parent = NULL; struct rb_node **p = &proc->threads.rb_node; while (*p) { parent = *p; thread = rb_entry(parent, struct binder_thread, rb_node); if (current->pid < thread->pid) p = &(*p)->rb_left; else if (current->pid > thread->pid) p = &(*p)->rb_right; else break; } ..... } 是当前的进程ID,它如何用于区分线程?

1 个答案:

答案 0 :(得分:1)

这是一个令人困惑的术语,但在内核级别,每个线程都分配了自己的pid值,该值唯一标识它。启动进程时,其第一个线程将被赋予唯一的pid,并且线程组ID将设置为相同的pid。创建新线程时,会为它们提供唯一的pid值但具有相同的线程组ID,以便它们可以链接回其父级。因此,您正在查看的这个rb树搜索代码将起作用,因为current->pid是当前正在执行的线程ID,它正在与树中线程条目的thread->pid值进行比较。

如果您感兴趣,来自这个SO问题的paxdiablo的答案更详细地解释了线程/进程ID: If threads share the same PID, how can they be identified?

相关问题