I'm learning binder driver. It has a struct binder_thread
for saving thread info. I find that it uses binder_thread.pid
that is assigned with current->pid
to distinguish each others. for example, in binder_get_thread
method, that field is used to judge whether current thread has been add to the tree.
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;
}
.....
}
But as I known, current->pid
is the current process id, how can it be used for distinguishing threads?