This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Launching tasks from a class

I am coding a c++ wrapper to listen messages coming from the CAN bus for an ARM7 processor, and need to launch a task for callback function. I define the callback function as static as usual when using threads. When compiling the following error appears:

error: #167: argument of type "void (*)(void*)" is incompatible with parameter of type "void (*)(void *) C"

What am i doing wrong? It is possible to launch a task inside a class?

Source code sample:

void taskCallBack( void* pthis ) __task;

class BusCAN
{
public:
        CAN_ERROR start( bool listen );
        virtual void onMessage( CAN_msg *msg ) = NULL;

private:
        static void taskCallBack( void* pthis ) __task;

// ...
};


CAN_ERROR BusCAN::start( bool listen )
{
    CAN_ERROR canError = CAN_start( CANCtrl );
    os_tsk_create_ex( taskCallBack, listenPriority, this );
    return canError;
}

void taskCallBack( void* pthis ) __task
{
  CAN_msg msg_rece;

  for (;;)
  {
    // Do something
  }
}

Thanks in advance.

  • is the

    taskCallBack
    

    with the infinite loop the same that you refer to earlier? if so, why then doesn't the definition look like this:

    void BusCAN::taskCallBack( void* pthis ) __task
    


    did you check the prototype of

    os_tsk_create_ex
    

    ? are you sure it can accept a member function...?

  • Thanks for the answer, and sorry, you're right: the source code is incomplete.

    At the moment, I tried with three posibilities:

    1.- As member function, my first try (but os_tsk_createXXX does not accept member functions, that was the expected behaviour).

    void BusCAN::taskCallBack() __task
    

    2.- As static member function: message error:
    "error: #167: argument of type "void (*)(void*)" is incompatible with parameter of type "void (*)(void *) C"

    static void BusCAN::taskCallBack( void* pthis ) __task
    

    3. As friend function of the BusCAN class: same error message as above.

    void taskCallBack( void* pthis ) __task
    

    My experience with this come from using POSIX threads into classes, and the easiest workaround was using static member functions to define thread behaviour. I think this is a similar case.

    Hope this helps to show what I am trying to do. Thanks.