如何使用包装函数传入函数的参数指针函数?

Arm*_*ian 5 c pthreads wrapper

我有这个功能:

void boot(uint ncores, uint nterm, Task boot_task, int argl, void* args)
{

 for(int i=0; i<MAX_PROC;i++) {
    PT[i].ppid = NOPROC;
 }
 nextproc = 0;

 curproc = NOPROC;
 Exec(boot_task, argl, args);
}
Run Code Online (Sandbox Code Playgroud)

而且我想要而不是Exec()使用pthread,所以我必须调用cpu_boot:

void cpu_boot(uint cores, interrupt_handler bootfunc, uint serialno)
{
 //I cannot change this function 
}
Run Code Online (Sandbox Code Playgroud)

这些是参数的类型

typedef void interrupt_handler();
typedef int (* Task)(int, void*);
Run Code Online (Sandbox Code Playgroud)

我试过了:

void boot(uint ncores, uint nterm, Task boot_task, int argl, void* args)
{
    void my_wrapper()
    {

        int y;
        y= boot_task(argl, args);
    }

    cpu_boot(ncores, my_wrapper , nterm);
}
Run Code Online (Sandbox Code Playgroud)

但这是错误的.我该如何实现呢?

d.j*_*tta 2

你会想要这样的东西:

void some_interrupt_handler(){
    /* code here */
    return;
}

interrupt_handler* my_wrapper(Task boot_task, int argl, void* args)
{
    /* 
      this is where you run boot task
    */
    boot_task(argl, args);

    /* then pick an interrupt_handler to return... */
    void (*function_ptr)() = some_interrupt_handler;

    return function_ptr;
}
Run Code Online (Sandbox Code Playgroud)

然后你可以像这样使用你的包装器:

void boot(uint ncores, uint nterm, Task boot_task, int argl, void* args)
{
    cpu_boot(ncores, my_wrapper(boot_task, argl, args) , nterm);
}
Run Code Online (Sandbox Code Playgroud)