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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top