Remove std::function from AlgoExecutionTask constructor
Prompted by a comment from @graven:
The suggestion is to drop the requirement of std::function<StatusCode()>
as argument to AlgoExecutionTask
-- as there is no reason to have it. Instead, make AlgoExecutionTask
a templated class:
template<typename Fun>
class AlgoExecutionTask : public tbb::task
{
public:
AlgoExecutionTask( IAlgorithm* algorithm, EventContext* ctx, ISvcLocator* svcLocator, IAlgExecStateSvc* aem,
Fun promote2ExecutedClosure )
: m_algorithm( algorithm )
, m_evtCtx( ctx )
, m_aess( aem )
, m_serviceLocator( svcLocator )
, m_promote2ExecutedClosure( std::move( promote2ExecutedClosure ) ){};
tbb::task* execute() override;
private:
SmartIF<IAlgorithm> m_algorithm;
EventContext* m_evtCtx;
IAlgExecStateSvc* m_aess;
SmartIF<ISvcLocator> m_serviceLocator;
Fun m_promote2ExecutedClosure;
};
And, in case not yet using C++17, add a small helper to make an AlgoExecutionTask
by determining the type of Fun
...
This will reduce the number of memory allocations (as std::function
has to make one for the type erasure), and saves
on a virtual memory call (again, required by the type erasure implied by std::function
).
Note that this is possible because AlgoExecutionTask
is never really used polymorphically -- it is there to implement
the execute
function of its base class, and that is the class which is used polymorphically.
Note that in the LHCb HltControlFlowManager this idea is taking to the max, and the interface to TBB is reduced to a single function which takes any lambda (with the correct signature). The lambda is then wrapped into a generic TBB task, see here.
Maybe this code could be moved back into Gaudi...