Skip to content

vtkThreadedCallbackQueue: fixing behavior of Invoker

The Invoker structure was not handling correctly all types of input functions;

  • When the parameters of the input function were lvalue references, it was not capable to pass its internally stored parameters as lvalue references when invoking the function
  • The input functors were stored as lvalue references. This can be problematic if the functor has been destroyed before it is invoked.
  • There was no way to pass member function pointers

To fix those issues, a few changes were made:

  • There is a meta class ArgType that statically casts the stored parameters to the type of the parameters of the function. It uses another meta class Signature whose job is to extract the types of the function parameters.
  • The type of the stored Function is dereferenced, which forces a copy constructor call if the input is an lvalue reference.
  • A specialized instance of Invoker can now hold a member function pointer. This is done by defering the storing management to a new FunctionHandle class that is set as a member of Invoker. There is a specialized version of FunctionHandle member function pointers.

Forcing to call a copy constructor if you do not want to give up ownership is somewhat limiting. So the queue can now accept smart pointers as inputs for functors and class instances (in the case of a member function pointer passing). This is allowed by the meta class Dereference

The documentation of Push is more extensive, giving examples of who the function can be called.

The test has been augmented to ensure that all scenarios deemed possible by the documentation actually compile

Edited by Yohann Bearzi (Kitware)

Merge request reports