Pergunta

Linux kernel has the following definition inside sched_class struct definition.

#ifdef CONFIG_SMP
  int  (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);
  .......
  .......

Now what does this line mean, I have fairly good knowledge in C & C++. But I was having hard time understanding this declaration construct:

 int  (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);

Can someone please explain what does this mean and what it does.

Thanks

Foi útil?

Solução

It's a function pointer.

int (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);

means that select_task_rq is a pointer to a function returning an int and taking all those parameter types.

It can be set to any compatible function and called as if it were a fixed function name. It's sometimes used to provide a primitive form of polymorphism in C, or to allow easy switching between functions based on other information.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top