Commit 714ef083 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Merge branch 'RefactorContextPointer' into 'master'

Avoid using a (possibly invalid) EventContext pointer

See merge request !719
parents 05562958 5a277723
......@@ -581,7 +581,7 @@ StatusCode AvalancheSchedulerSvc::tryPopFinishedEvent( EventContext*& eventConte
* * No algorithms have been signed off by the data flow
* * No algorithms have been scheduled
*/
StatusCode AvalancheSchedulerSvc::updateStates( int si, const int algo_index, EventContext* inputContext )
StatusCode AvalancheSchedulerSvc::updateStates( int si, const int algo_index, const int sub_slot )
{
StatusCode global_sc( StatusCode::SUCCESS );
......@@ -614,16 +614,14 @@ StatusCode AvalancheSchedulerSvc::updateStates( int si, const int algo_index, Ev
if ( algo_index >= 0 ) {
Cause cs = {Cause::source::Task, index2algname( algo_index )};
// Pass sub-slots to precedence service if necessary
if ( !inputContext || iSlot != (int)inputContext->slot() || inputContext == thisSlot.eventContext ) {
// Pass sub-slots to precedence service if a sub-slot index is given
if ( sub_slot == -1 ) {
if ( m_precSvc->iterate( thisSlot, cs ).isFailure() ) {
error() << "Failed to call IPrecedenceSvc::iterate for slot " << iSlot << endmsg;
global_sc = StatusCode::FAILURE;
}
} else {
// An input context that doesn't match the event context for that slot number implies a sub-slot
unsigned int const subSlotIndex = thisSlot.contextToSlot.at( inputContext );
if ( m_precSvc->iterate( thisSlot.allSubSlots[subSlotIndex], cs ).isFailure() ) {
if ( m_precSvc->iterate( thisSlot.allSubSlots[sub_slot], cs ).isFailure() ) {
error() << "Failed to call IPrecedenceSvc::iterate for sub-slot of " << iSlot << endmsg;
global_sc = StatusCode::FAILURE;
}
......@@ -1032,13 +1030,14 @@ StatusCode AvalancheSchedulerSvc::promoteToExecuted( unsigned int iAlgo, int si,
AState state = algo->filterPassed() ? AState::EVTACCEPTED : AState::EVTREJECTED;
// Update states in the appropriate slot
int subSlotIndex = -1;
if ( eventContext == thisSlot.eventContext ) {
// Event level (standard behaviour)
sc = thisSlot.algsStates.set( iAlgo, state );
} else {
// Sub-slot
unsigned int const subSlotIndex = thisSlot.contextToSlot.at( eventContext );
sc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, state );
subSlotIndex = static_cast<int>( thisSlot.contextToSlot.at( eventContext ) );
sc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, state );
}
ON_VERBOSE if ( sc.isSuccess() ) verbose() << "Promoting " << algo->name() << " on slot " << si << " to " << state
......@@ -1049,9 +1048,9 @@ StatusCode AvalancheSchedulerSvc::promoteToExecuted( unsigned int iAlgo, int si,
// Schedule an update of the status of the algorithms
++m_actionsCounts[si];
m_actionsQueue.push( [this, si, iAlgo, eventContext]() {
m_actionsQueue.push( [this, si, iAlgo, subSlotIndex]() {
--this->m_actionsCounts[si]; // no bound check needed as decrements/increments are balanced in the current setup
return this->updateStates( -1, iAlgo, eventContext );
return this->updateStates( -1, iAlgo, subSlotIndex );
} );
return sc;
......@@ -1087,13 +1086,14 @@ StatusCode AvalancheSchedulerSvc::promoteToAsyncExecuted( unsigned int iAlgo, in
AState state = algo->filterPassed() ? AState::EVTACCEPTED : AState::EVTREJECTED;
// Update states in the appropriate slot
int subSlotIndex = -1;
if ( eventContext == thisSlot.eventContext ) {
// Event level (standard behaviour)
sc = thisSlot.algsStates.set( iAlgo, state );
} else {
// Sub-slot
unsigned int const subSlotIndex = thisSlot.contextToSlot.at( eventContext );
sc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, state );
subSlotIndex = static_cast<int>( thisSlot.contextToSlot.at( eventContext ) );
sc = thisSlot.allSubSlots[subSlotIndex].algsStates.set( iAlgo, state );
}
ON_VERBOSE if ( sc.isSuccess() ) verbose() << "[Asynchronous] Promoting " << algo->name() << " on slot " << si
......@@ -1104,9 +1104,9 @@ StatusCode AvalancheSchedulerSvc::promoteToAsyncExecuted( unsigned int iAlgo, in
// Schedule an update of the status of the algorithms
++m_actionsCounts[si];
m_actionsQueue.push( [this, si, iAlgo, eventContext]() {
m_actionsQueue.push( [this, si, iAlgo, subSlotIndex]() {
--this->m_actionsCounts[si]; // no bound check needed as decrements/increments are balanced in the current setup
return this->updateStates( -1, iAlgo, eventContext );
return this->updateStates( -1, iAlgo, subSlotIndex );
} );
return sc;
......
......@@ -230,7 +230,7 @@ private:
/// Loop on algorithm in the slots and promote them to successive states
/// (-1 for algo_index means skipping an update of the Control Flow state)
StatusCode updateStates( int si = -1, int algo_index = -1, EventContext* = nullptr );
StatusCode updateStates( int si = -1, int algo_index = -1, int sub_slot = -1 );
/// Algorithm promotion
StatusCode promoteToScheduled( unsigned int iAlgo, int si, EventContext* );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment